Class: Churn::ChurnCalculator
- Inherits:
-
Object
- Object
- Churn::ChurnCalculator
- Defined in:
- lib/churn/churn_calculator.rb
Instance Method Summary collapse
- #analyze ⇒ Object
- #emit ⇒ Object
-
#initialize(options = {}) ⇒ ChurnCalculator
constructor
A new instance of ChurnCalculator.
- #report(print = true) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ChurnCalculator
Returns a new instance of ChurnCalculator.
19 20 21 22 23 24 25 26 27 |
# File 'lib/churn/churn_calculator.rb', line 19 def initialize(={}) start_date = .fetch(:start_date) { '3 months ago' } @minimum_churn_count = .fetch(:minimum_churn_count) { 5 } @source_control = set_source_control(start_date) @changes = {} @revision_changes = {} @class_changes = {} @method_changes = {} end |
Instance Method Details
#analyze ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/churn/churn_calculator.rb', line 40 def analyze @changes = @changes.to_a.sort {|x,y| y[1] <=> x[1]} @changes = @changes.map {|file_path, times_changed| {:file_path => file_path, :times_changed => times_changed }} calculate_revision_changes @method_changes = @method_changes.to_a.sort {|x,y| y[1] <=> x[1]} @method_changes = @method_changes.map {|method, times_changed| {'method' => method, 'times_changed' => times_changed }} @class_changes = @class_changes.to_a.sort {|x,y| y[1] <=> x[1]} @class_changes = @class_changes.map {|klass, times_changed| {'klass' => klass, 'times_changed' => times_changed }} end |
#emit ⇒ Object
35 36 37 38 |
# File 'lib/churn/churn_calculator.rb', line 35 def emit @changes = parse_log_for_changes.reject {|file, change_count| change_count < @minimum_churn_count} @revisions = parse_log_for_revision_changes end |
#report(print = true) ⇒ Object
29 30 31 32 33 |
# File 'lib/churn/churn_calculator.rb', line 29 def report(print = true) self.emit self.analyze print ? self.to_s : self.to_h end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/churn/churn_calculator.rb', line 52 def to_h hash = {:churn => {:changes => @changes}} hash[:churn][:class_churn] = @class_changes hash[:churn][:method_churn] = @method_changes #detail the most recent changes made this revision if @revision_changes[@revisions.first] changes = @revision_changes[@revisions.first] hash[:churn][:changed_files] = changes[:files] hash[:churn][:changed_classes] = changes[:classes] hash[:churn][:changed_methods] = changes[:methods] end #TODO crappy place to do this but save hash to revision file but while entirely under metric_fu only choice ChurnHistory.store_revision_history(@revisions.first, hash) hash end |
#to_s ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/churn/churn_calculator.rb', line 68 def to_s hash = to_h result = seperator result +="* Revision Changes \n" result += seperator result += "Files: \n" result += display_array(hash[:churn][:changed_files], :fields=>[:to_str], :headers=>{:to_str=>'file'}) result += "\nClasses: \n" result += display_array(hash[:churn][:changed_classes]) result += "\nMethods: \n" result += display_array(hash[:churn][:changed_methods]) + "\n" result += seperator result +="* Project Churn \n" result += seperator result += "Files: \n" result += display_array(hash[:churn][:changes]) result += "\nClasses: \n" class_churn = hash[:churn][:class_churn].map {|e| (e.delete('klass') || {}).merge(e) } result += display_array(class_churn) result += "\nMethods: \n" method_churn = hash[:churn][:method_churn].map {|e| (e.delete('method') || {}).merge(e) } result += display_array(method_churn) end |