class Coco::ConsoleFormatter
I format coverages data for console output.
Public Class Methods
new(uncovered, threshold, result, config)
click to toggle source
Public: Creates a new ConsoleFormatter
.
uncovered - An Array list of uncovered files. threshold - The Fixnum percentage threshold. result - A CoverageResult
. config - A Configuration
.
# 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
Public Instance Methods
format()
click to toggle source
Public: Get a colored report, formatted for console output.
Returns percent covered and associated filenames as a multilines or a single line String.
# File lib/coco/formatter/console_formatter.rb, line 12 def format @config[:single_line_report] ? single_line_message : multilines_message end
link()
click to toggle source
Get the link for the report's index file.
Returns String.
# 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
Private Instance Methods
add_percentage_to_uncovered()
click to toggle source
# File lib/coco/formatter/console_formatter.rb, line 66 def add_percentage_to_uncovered @uncovered.each { |filename| @formatted_output << [0, filename] } end
compute_percentage()
click to toggle source
# File lib/coco/formatter/console_formatter.rb, line 59 def compute_percentage @result.not_covered_enough.each do |filename, coverage| percentage = CoverageStat.coverage_percent(coverage) @formatted_output << [percentage, filename] end end
multilines_message()
click to toggle source
# File lib/coco/formatter/console_formatter.rb, line 74 def multilines_message @formatted_output.join("\n") + "\n" + @summary.to_s + "\n" end
single_line_message()
click to toggle source
# File lib/coco/formatter/console_formatter.rb, line 70 def single_line_message ColoredString.new(@summary.to_s).yellow end