Sha256: f588a64f530f574b3e74b2c8bfc8d3136e75dbd7ee06910512da0a53de44dbaa

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

module MetricFu

  class Stats < Generator

    def emit
      command = %Q(rake 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

2 entries across 2 versions & 1 rubygems

Version Path
metric_fu-2.1.4.pre2 lib/metric_fu/metrics/stats/stats.rb
metric_fu-2.1.4.pre lib/metric_fu/metrics/stats/stats.rb