class Minitest::RubyGolfMetrics::Reporter

Public Instance Methods

record(erg) click to toggle source
# File lib/minitest/ruby_golf_metrics/reporter.rb, line 13
def record(erg)
  method_definition = erg.location.
    gsub("RubyGolfTest#test_", "").
    gsub(/ .*$/, "").
    gsub(/_[0-9]$/, "").
    gsub(/hole_([0-9]+)_/, "\\1#")
  @ergs[method_definition] ||= []
  @ergs[method_definition] << erg.passed?
end
report() click to toggle source
# File lib/minitest/ruby_golf_metrics/reporter.rb, line 23
def report
  io.puts "\nRuby Golf Metrics"
  @ergs.sort.each do |method_definition, ergs|
    (hole, method_name) = method_definition.split("#")
    begin
      if ergs.all?
        begin
          counter = CharacterCounter.new(method_name)
          msg = "  #{colorize(hole, method_name, 32)}: #{counter.cumulative_size} character(s)"
          msg << " (#{counter.called_method_sizes.join(", ")})" if !counter.self_contained?
          io.puts msg
        rescue NoMethodError
          io.puts "  #{colorize(hole, method_name, 31)}: UNDEFINED"
        end
      else
        io.puts "  #{colorize(hole, method_name, 31)}: FAILED"
      end
    rescue
      io.puts "  #{colorize(hole, method_name, 31)}: there was an error counting your characters"
    end
  end
end
start() click to toggle source
# File lib/minitest/ruby_golf_metrics/reporter.rb, line 9
def start
  @ergs = {}
end

Private Instance Methods

colorize(hole, method_name, color) click to toggle source
# File lib/minitest/ruby_golf_metrics/reporter.rb, line 48
def colorize(hole, method_name, color)
  text = "Hole #{hole} (#{method_name})"
  options[:nocolor] ? text : "\e[#{color}m#{text}\e[0m"
end