Sha256: 62dc852c8ae372e85e61a4df0c689cd7e03396124e7201eb178ee90de4b8cfa1

Contents?: true

Size: 1.41 KB

Versions: 11

Compression:

Stored size: 1.41 KB

Contents

module MetricFu

  class Stats < Generator

    def emit
      command = %Q(mf-stats > #{metric_directory + '/stats.txt'})
      mf_debug "** #{command}"
      @output = `#{command}`
    end

    def analyze
      output = File.open(metric_directory + '/stats.txt').read
      lines = remove_noise(output)

      @stats = {}

      set_global_stats(lines.pop)
      set_granular_stats(lines)

      @stats
    end

    def to_h
      {:stats => @stats}
    end

    private

    def remove_noise(output)
      lines = output.split("\n")
      lines = lines.find_all {|line| line =~ /^\s*[C|]/ }
      lines.shift
      lines
    end

    def set_global_stats(totals)
      totals = totals.split("  ").find_all {|el| ! el.empty? }
      @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
    end

    def set_granular_stats(lines)
      @stats[:lines] = lines.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
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
metric_fu-4.2.1 lib/metric_fu/metrics/stats/stats.rb
metric_fu-4.2.0 lib/metric_fu/metrics/stats/stats.rb
metric_fu-4.1.3 lib/metric_fu/metrics/stats/stats.rb
metric_fu-4.1.2 lib/metric_fu/metrics/stats/stats.rb
metric_fu-4.1.1 lib/metric_fu/metrics/stats/stats.rb
metric_fu-4.1.0 lib/metric_fu/metrics/stats/stats.rb
metric_fu-4.0.0 lib/metric_fu/metrics/stats/stats.rb
metric_fu-3.0.1 lib/metric_fu/metrics/stats/stats.rb
metric_fu-3.0.0 lib/metric_fu/metrics/stats/stats.rb
metric_fu-2.1.4.pre5 lib/metric_fu/metrics/stats/stats.rb
metric_fu-2.1.4.pre4 lib/metric_fu/metrics/stats/stats.rb