Class: Churn::ChurnCalculator

### Home Classes Methods

### In Files

- lib/churn/churn_calculator.rb

### Parent

Object

### Methods

- ::new
- #analyze
- #emit
- #report
- #to_h
- #to_s

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Churn
- Churn::ChurnCalculator
- Churn::ChurnHistory
- Churn::GitAnalyzer
- Churn::HgAnalyzer
- Churn::LocationMapping
- Churn::SourceControl
- Churn::SvnAnalyzer
- Object

No matching classes.

# Churn::ChurnCalculator

### Public Class Methods

new(options={}) click to toggle source

intialized the churn calculator object

    # File lib/churn/churn_calculator.rb, line 21
    def initialize(options={})
      start_date = options.fetch(:start_date) { '3 months ago' }
      @minimum_churn_count = options.fetch(:minimum_churn_count) { 5 }
      @source_control = set_source_control(start_date)
      @changes          = {}
      @revision_changes = {}
      @class_changes    = {}
      @method_changes   = {}
    end

### Public Instance Methods

analyze() click to toggle source

Analyze the source control data, filter, sort, and find more information on the editted files

    # File lib/churn/churn_calculator.rb, line 48
    def analyze
      @changes = sort_changes(@changes)
      @changes = @changes.map {|file_path, times_changed| {:file_path => file_path, :times_changed => times_changed }}

      calculate_revision_changes

      @method_changes = sort_changes(@method_changes)
      @method_changes = @method_changes.map {|method, times_changed| {'method' => method, 'times_changed' => times_changed }}
      @class_changes  = sort_changes(@class_changes)
      @class_changes  = @class_changes.map {|klass, times_changed| {'klass' => klass, 'times_changed' => times_changed }}
    end

emit() click to toggle source

Emits various data from source control to be analyses later… Currently this is broken up like this as a throwback to metric_fu

    # File lib/churn/churn_calculator.rb, line 42
    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) click to toggle source

prepares the data for the given project to be reported. reads git/svn logs analyzes the output, generates a report and either formats as a nice string or returns hash. @param [Bolean] format to return the data, true for string or false for hash @return [Object] returns either a pretty string or a hash representing the chrun of the project

    # File lib/churn/churn_calculator.rb, line 35
    def report(print = true)
      self.emit
      self.analyze
      print ? self.to_s : self.to_h
    end

to_h() click to toggle source

collect all the data into a single hash data structure.

    # File lib/churn/churn_calculator.rb, line 61
    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() click to toggle source

Pretty print the data as a string for the user

    # File lib/churn/churn_calculator.rb, line 78
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.