Sha256: 9fc935370ece5e52ba55dc6a2dadb3365c415ce203e0b1e41929016a228cc45e
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require "json" module RailsStats class JSONFormatter < StatsFormatter def result @result = @statistics.map { |key, stats| stat_hash(key, stats) } if @grand_total @result << stat_hash("Total", @grand_total).merge(code_test_hash) end @result end def to_s puts result.to_json end private def code_test_hash code = calculator.code_loc tests = calculator.test_loc { "code_to_test_ratio" => "#{sprintf("%.1f", tests.to_f/code)}", "total" => true } end def stat_hash(name, statistics) m_over_c = (statistics.methods / statistics.classes) rescue m_over_c = 0 loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0 { "name" => name, "files" => statistics.files_total.to_s, "lines" => statistics.lines.to_s, "loc" => statistics.code_lines.to_s, "classes" => statistics.classes.to_s, "methods" => statistics.methods.to_s, "m_over_c" => m_over_c.to_s, "loc_over_m" => loc_over_m.to_s } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_stats-2.0.1 | lib/rails_stats/json_formatter.rb |
rails_stats-2.0.0 | lib/rails_stats/json_formatter.rb |