Class: MetricFu::Stats

Inherits:
Generator show all
Defined in:
lib/generators/stats.rb

Instance Attribute Summary

Attributes inherited from Generator

#report, #template

Instance Method Summary collapse

Methods inherited from Generator

class_name, #create_data_dir_if_missing, #create_metric_dir_if_missing, #create_output_dir_if_missing, generate_report, #generate_report, #initialize, #metric_directory, metric_directory, #remove_excluded_files, #round_to_tenths, #to_graph, verify_dependencies!

Constructor Details

This class inherits a constructor from MetricFu::Generator

Instance Method Details

#analyzeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/stats.rb', line 9

def analyze
  output = File.open(metric_directory + '/stats.txt').read
  output = output.split("\n")
  output = output.find_all {|line| line[0].chr != "+" }
  output = output.find_all {|line| line[0].chr != "(" }
  output.shift
  totals = output.pop
  totals = totals.split("  ").find_all {|el| ! el.empty? }
  @stats = {}
  @stats[:codeLOC] = totals[0].match(/\d.*/)[0].to_i
  @stats[:testLOC] = totals[1].match(/\d.*/)[0].to_i
  @stats[:code_to_test_ratio] = totals[2].match(/1\:(\d.*)/)[1].to_f
  
  @stats[:lines] = output.map do |line|
    elements = line.split("|")
    elements.map! {|el| el.strip }
    elements = elements.find_all {|el| ! el.empty? }
    info_line = {}
    info_line[:name] = elements.shift
    elements.map! {|el| el.to_i }
    [:lines, :loc, :classes, :methods, 
     :methods_per_class, :loc_per_method].each do |sym|
      info_line[sym] = elements.shift
    end
    info_line
  end
  @stats
end

#emitObject



5
6
7
# File 'lib/generators/stats.rb', line 5

def emit
  `rake stats > #{metric_directory + '/stats.txt'}`
end

#to_hObject



38
39
40
# File 'lib/generators/stats.rb', line 38

def to_h
  {:stats => @stats}
end