Class: Coco::ConsoleFormatter

Inherits:
Formatter 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(covered, uncovered, threshold) ⇒ ConsoleFormatter

Public: Creates a new ConsoleFormatter.

covered - See base class Formatter. uncovered - See base class Formatter. threshold - The Fixnum percentage threshold.



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

def initialize(covered, uncovered, threshold)
  super(covered, uncovered)
  @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
end

Instance Method Details

#format(single_line_report = false) ⇒ Object

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

single_line_report - Boolean

Returns percent covered and associated filenames as a multilines String



14
15
16
# File 'lib/coco/formatter/console_formatter.rb', line 14

def format(single_line_report = false)
  single_line_report ? single_line_message : @formatted_output.join("\n")
end

Get the link for the report's index file.

Returns String.



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

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