lib/churn/churn_calculator.rb in churn-0.0.29 vs lib/churn/churn_calculator.rb in churn-0.0.30
- old
+ new
@@ -11,26 +11,30 @@
require 'svn_analyzer'
require 'hg_analyzer'
require 'bzr_analyzer'
require 'location_mapping'
require 'churn_history'
+require 'churn_options'
module Churn
- # The work horse of the the churn library. This class takes user input, determins the SCM the user is using. It then determines changes
- # made during this revision. Finally it reads all the changes from previous revisions and displays human readable output to the command
- # line. It can also ouput a yaml format readable by other tools such as metric_fu and Caliper.
+ # The work horse of the the churn library.
+ # This class takes user input, determins the SCM the user is using.
+ # It then determines changes made during this revision.
+ # Finally it reads all the changes from previous revisions and displays human readable output on the command line.
+ # It can also ouput a yaml format readable by other tools such as metric_fu and Caliper.
class ChurnCalculator
# intialized the churn calculator object
def initialize(options={})
- options[:start_date]=nil if options[:start_date]==''
- start_date = options.fetch(:start_date) { '3 months ago' }
- @minimum_churn_count = options.fetch(:minimum_churn_count) { 5 }.to_i
- @ignore_files = (options.fetch(:ignore_files){ "" }).to_s.split(',').map(&:strip)
- @ignore_files << '/dev/null'
- @source_control = set_source_control(start_date)
+ @churn_options = ChurnOptions.instance.set_options(options)
+
+ @minimum_churn_count = @churn_options.minimum_churn_count
+ @ignore_files = @churn_options.ignore_files
+ start_date = @churn_options.start_date
+ @source_control = set_source_control(start_date)
+
@changes = {}
@revision_changes = {}
@class_changes = {}
@method_changes = {}
end
@@ -81,13 +85,11 @@
#TODO crappy place to do this but save hash to revision file but while entirely under metric_fu only choice
ChurnHistory.store_revision_history(first_revision, hash)
hash
end
- # Pretty print the data as a string for the user
- def to_s
- hash = to_h[:churn]
+ def self.to_s(hash)
result = seperator
result +="* Revision Changes \n"
result += seperator
result += "Files: \n"
result += display_array(hash[:changed_files], :fields=>[:to_str], :headers=>{:to_str=>'file'})
@@ -104,9 +106,14 @@
class_churn = collect_items(hash[:class_churn], 'klass')
result += display_array(class_churn)
result += "\nMethods: \n"
method_churn = collect_items(hash[:method_churn], 'method')
result += display_array(method_churn)
+ end
+
+ # Pretty print the data as a string for the user
+ def to_s
+ ChurnCalculator(to_h[:churn])
end
private
def collect_items(collection, match)