Class: BirthControl::Report
- Inherits:
-
Object
- Object
- BirthControl::Report
- Defined in:
- lib/birth_control/report.rb
Instance Method Summary collapse
- #class_instantiation_report ⇒ Object
- #count ⇒ Object
- #count_class(klass) ⇒ Object
- #count_class_and_id(klass, id) ⇒ Object
- #duplication_report ⇒ Object
-
#initialize(results) ⇒ Report
constructor
A new instance of Report.
- #to_s ⇒ Object
Constructor Details
#initialize(results) ⇒ Report
Returns a new instance of Report.
3 4 5 |
# File 'lib/birth_control/report.rb', line 3 def initialize(results) @results = results end |
Instance Method Details
#class_instantiation_report ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/birth_control/report.rb', line 40 def class_instantiation_report lines = ["*** [BirthControl] Class instantiation overview ***"] @results.each do |klass, _| count = "%5s" % count_class(klass) lines << "#{count} #{klass.pluralize}" end lines << "#{"%5s" % count} Total" lines.join("\n") + "\n" end |
#count ⇒ Object
15 16 17 |
# File 'lib/birth_control/report.rb', line 15 def count @results.inject(0) { |c, (klass, _)| c + count_class(klass) } end |
#count_class(klass) ⇒ Object
11 12 13 |
# File 'lib/birth_control/report.rb', line 11 def count_class(klass) @results[klass].inject(0) { |c, (id, _)| c + count_class_and_id(klass, id) } end |
#count_class_and_id(klass, id) ⇒ Object
7 8 9 |
# File 'lib/birth_control/report.rb', line 7 def count_class_and_id(klass, id) @results[klass][id].size end |
#duplication_report ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/birth_control/report.rb', line 19 def duplication_report lines = [] @results.each do |klass, entries| entries.each do |id, callers| if callers.size > 1 lines << "\n#{klass}(#{id}) - #{callers.size} times" callers.each_with_index do |caller, index| occurence = caller.detect { |call| call.match(/app\//) } occurence.sub!(/(.*)\/app\//, 'app/') lines << " #{index+1}. #{occurence}" end end end end if lines.size > 0 lines.unshift "*** [BirthControl] Duplicate instantiation detected ***" lines.join("\n") + "\n" end end |
#to_s ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/birth_control/report.rb', line 50 def to_s lines = [ '[BirthControl]', class_instantiation_report, duplication_report ] lines.join "\n" end |