Class: SandiMeter::Formatter
- Inherits:
-
Object
- Object
- SandiMeter::Formatter
- Defined in:
- lib/sandi_meter/formatter.rb
Instance Method Summary collapse
Instance Method Details
#print_data(data) ⇒ Object
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 |
# File 'lib/sandi_meter/formatter.rb', line 3 def print_data(data) if data[:first_rule][:total_classes_amount] > 0 puts "1. #{data[:first_rule][:small_classes_amount] * 100 / data[:first_rule][:total_classes_amount]}% of classes are under 100 lines." else puts "1. No classes to analyze." end if data[:second_rule][:total_methods_amount] > 0 puts "2. #{data[:second_rule][:small_methods_amount] * 100 / data[:second_rule][:total_methods_amount]}% of methods are under 5 lines." else puts "2. No methods to analyze." end if data[:third_rule][:total_method_calls] > 0 puts "3. #{data[:third_rule][:proper_method_calls] * 100 / data[:third_rule][:total_method_calls]}% of method calls accepted are less than 4 parameters." else puts "3. No method calls to analyze." end if data[:fourth_rule][:total_controllers_amount] > 0 puts "4. #{data[:fourth_rule][:proper_controllers_amount] * 100 / data[:fourth_rule][:total_controllers_amount]}% of controllers have one instance variable per action." else puts "4. No controllers to analyze." end print_log(data) end |
#print_log(data) ⇒ Object
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 60 61 62 63 |
# File 'lib/sandi_meter/formatter.rb', line 31 def print_log(data) return unless data[:first_rule][:log] || data[:second_rule][:log] || data[:fourth_rule][:log] if data[:first_rule][:log][:classes].any? puts "\nClasses with 100+ lines" print_array_of_arrays [["Class name", "Size", "Path"]] + data[:first_rule][:log][:classes] end if data[:first_rule][:log][:misindented_classes].any? puts "\nMisindented classes" print_array_of_arrays [["Class name", "Path"]] + data[:first_rule][:log][:misindented_classes].map { |row| row.delete_at(1); row } # 1 – size, which nil for misindented_classes end if data[:second_rule][:log][:methods].any? puts "\nMethods with 5+ lines" print_array_of_arrays [["Class name", "Method name", "Size", "Path"]] + data[:second_rule][:log][:methods] end if data[:second_rule][:log][:misindented_methods].any? puts "\nMisindented methods" print_array_of_arrays [["Class name", "Method name", "Path"]] + data[:second_rule][:log][:misindented_methods].map { |row| row.delete_at(2); row } # 2 – size, which nil for misindented_methods end if data[:third_rule][:log][:method_calls].any? puts "\nMethod calls with 4+ arguments" print_array_of_arrays [["# of arguments", "Path"]] + data[:third_rule][:log][:method_calls] end if data[:fourth_rule][:log][:controllers].any? puts "\nControllers with 1+ instance variables" print_array_of_arrays [["Controller name", "Action name", "Instance variables"]] + data[:fourth_rule][:log][:controllers] end end |