-
Notifications
You must be signed in to change notification settings - Fork 3
/
reek_parser.rb
59 lines (52 loc) · 1.52 KB
/
reek_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'yaml'
class ReekYamlFile
def initialize(path)
@path = path
unless File.exist?(@path) : raise "no such file or directory" end
file_load
unless file_yaml? : raise "input file is not YAML format" end
unless file_reek_output? : raise "input file is not reek output" end
end
def to_reeks; @content; end
private
def file_load; File::open(@path) {|f| @content = YAML.load(f) }; end
def file_yaml?; @content != false; end
def file_reek_output?; @content.first.class == Reek::SmellWarning; end
end
class ReeksList
attr_reader :divide_reeks
def initialize(input_file_path)
@raw_reeks = ReekYamlFile.new(input_file_path).to_reeks
@divide_reeks = []
divide_by_context_class
sort_by_warning_num
end
def each
@divide_reeks.each {| reeks | yield(reeks)}
end
def each_with_index
@divide_reeks.each_with_index {| reeks, i | yield(reeks, i)}
end
def context_class_list
@divide_reeks.map{|reeks| reeks.first.context_class}
end
def total_warning_num
@divide_reeks.flatten.size
end
private
def divide_by_context_class
context_class_list = @raw_reeks.map{|reek| reek.context_class }.uniq
context_class_list.each do |context_class|
@divide_reeks << @raw_reeks.select{|reek| reek.context_class == context_class }
end
end
def sort_by_warning_num
@divide_reeks.sort!{|a, b| b.size <=> a.size}
end
end
module Reek
class SmellWarning
attr_accessor :smell, :location
def context_class; location["context"].split("#").first; end
end
end