Class: SimpleCov::Formatter::SummaryFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-summary.rb

Instance Method Summary collapse

Constructor Details

#initialize(output = nil) ⇒ SummaryFormatter

Returns a new instance of SummaryFormatter.



6
7
8
# File 'lib/simplecov-summary.rb', line 6

def initialize(output = nil)
  @output = output || STDOUT
end

Instance Method Details

#format(result) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simplecov-summary.rb', line 10

def format(result)
  @output.puts "SimpleCov stats:"

  name_length = (result.groups.keys + ["Total"]).map{|x| x.length}.max

  result.groups.each do |name, files|
    percentage = files.covered_percent.round(2)

    color = case percentage
    when 90..100
      :green
    when 80..90
      :yellow
    else
      :red
    end

    @output.puts "  #{name.rjust(name_length)}: #{percentage}%".colorize(color)
  end

  @output.puts "  #{'Total'.rjust(name_length)}: #{result.covered_percent.round(2)}%"
end