43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/sandi_meter/html_generator.rb', line 43
def generate_details!(path, data)
details = ""
if data[:first_rule][:log][:classes].any?
data[:first_rule][:log][:misindented_classes] ||= []
data[:first_rule][:log][:misindented_classes].each do |class_params|
class_params.insert(1, nil)
end
details << string_to_h2("Classes with 100+ lines")
details << generate_details_block(
["Class name", "Size", "Path"],
proper_data: data[:first_rule][:log][:classes],
warning_data: data[:first_rule][:log][:misindented_classes],
hint: "NOTE: Red classes are misindented. Start improving your project by fixing them.",
warning_message: 'Misindented classes'
)
end
if data[:second_rule][:log][:methods].any?
data[:second_rule][:log][:misindented_methods] ||= []
data[:second_rule][:log][:misindented_methods].each do |method_params|
method_params.insert(2, nil)
end
details << string_to_h2("Methods with 5+ lines")
details << generate_details_block(
["Class name", "Method name", "Size", "Path"],
proper_data: data[:second_rule][:log][:methods].sort_by { |a| -a[2].to_i },
warning_data: data[:second_rule][:log][:misindented_methods].sort_by { |a| -a[1].to_i },
hint: "NOTE: Red methods are misindented. Continue your way to perfect code by fixing them.",
warning_message: 'Misindented methods'
)
end
if data[:third_rule][:log][:method_calls].any?
details << string_to_h2("Method calls with 4+ arguments")
details << generate_details_block(
["# of arguments", "Path"],
proper_data: data[:third_rule][:log][:method_calls]
)
end
if data[:fourth_rule][:log][:controllers].any?
details << string_to_h2("Controllers with 1+ instance variables")
details << generate_details_block(
["Controller name", "Action name", "Instance variables"],
proper_data: data[:fourth_rule][:log][:controllers]
)
end
index_file = File.join(path, 'sandi_meter', 'index.html')
index = File.read(index_file)
index.gsub!('<% details %>', details)
File.open(index_file, 'w') do |file|
file.write(index)
end
end
|