Class: Coco::ConsoleFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/coco/formatter/console_formatter.rb

Overview

I format coverages data for console output.

Instance Method Summary collapse

Constructor Details

#initialize(uncovered, threshold, result, config) ⇒ ConsoleFormatter

Public: Creates a new ConsoleFormatter.

uncovered - An Array list of uncovered files. threshold - The Fixnum percentage threshold. result - A CoverageResult. config - A Configuration.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/coco/formatter/console_formatter.rb', line 35

def initialize(uncovered, threshold, result, config)
  @uncovered = uncovered
  @result = result

  @formatted_output = []
  compute_percentage
  add_percentage_to_uncovered
  @formatted_output.sort!
  @formatted_output.map! do |percentage, filename|
    text = ColoredString.new "#{percentage}% #{filename}"
    if percentage <= 50
      text.red
    elsif percentage >= threshold
      text.green
    else
      text.yellow
    end
  end
  @summary = Summary.new(result, uncovered)
  @config = config
end

Instance Method Details

#formatObject

Public: Get a colored report, formatted for console output.

Returns percent covered and associated filenames as a multilines or a single line String.



12
13
14
# File 'lib/coco/formatter/console_formatter.rb', line 12

def format
  @config[:single_line_report] ? single_line_message : multilines_message
end

Get the link for the report’s index file.

Returns String.



20
21
22
23
24
25
26
# File 'lib/coco/formatter/console_formatter.rb', line 20

def link
  unless @formatted_output.empty?
    'See file://' +
      File.expand_path(File.join(Coco::HtmlDirectory.new.coverage_dir,
                                 'index.html'))
  end
end