class Covered::Summary
Public Class Methods
new(threshold: 1.0)
click to toggle source
# File lib/covered/summary.rb, line 28 def initialize(threshold: 1.0) @threshold = threshold end
Public Instance Methods
call(wrapper, output = $stdout)
click to toggle source
A coverage array gives, for each line, the number of line execution by the interpreter. A nil value means coverage is disabled for this line (lines like else and end).
# File lib/covered/summary.rb, line 101 def call(wrapper, output = $stdout) terminal = self.terminal(output) statistics = self.each(wrapper) do |coverage| line_offset = 1 path = wrapper.relative_path(coverage.path) terminal.puts "" terminal.puts path, style: :path counts = coverage.counts coverage.read do |file| print_line_header(terminal) file.each_line do |line| count = counts[line_offset] print_annotations(terminal, coverage, line, line_offset) print_line(terminal, line, line_offset, count) line_offset += 1 end end coverage.print(output) end statistics.print(output) end
each(wrapper) { |coverage| ... }
click to toggle source
# File lib/covered/summary.rb, line 50 def each(wrapper) statistics = Statistics.new wrapper.each do |coverage| statistics << coverage if @threshold.nil? or coverage.ratio < @threshold yield coverage end end return statistics end
print_annotations(terminal, coverage, line, line_offset)
click to toggle source
# File lib/covered/summary.rb, line 64 def print_annotations(terminal, coverage, line, line_offset) if annotations = coverage.annotations[line_offset] prefix = "#{line_offset}|".rjust(8) + "*|".rjust(8) terminal.write prefix, style: :ignored_prefix terminal.write line.match(/^\s+/) terminal.puts "\# #{annotations.join(", ")}", style: :annotations end end
print_line(terminal, line, line_offset, count)
click to toggle source
# File lib/covered/summary.rb, line 80 def print_line(terminal, line, line_offset, count) prefix = "#{line_offset}|".rjust(8) + "#{count}|".rjust(8) if count == nil terminal.write prefix, style: :ignored_prefix terminal.write line, style: :ignored_code elsif count == 0 terminal.write prefix, style: :uncovered_prefix terminal.write line, style: :uncovered_code else terminal.write prefix, style: :covered_prefix terminal.write line, style: :covered_code end # If there was no newline at end of file, we add one: unless line.end_with? $/ terminal.puts end end
print_line_header(terminal)
click to toggle source
# File lib/covered/summary.rb, line 74 def print_line_header(terminal) prefix = "Line|".rjust(8) + "Hits|".rjust(8) terminal.puts prefix, style: :header_prefix end
terminal(output)
click to toggle source
# File lib/covered/summary.rb, line 32 def terminal(output) Console::Terminal.for(output).tap do |terminal| terminal[:path] ||= terminal.style(nil, nil, :bold, :underline) terminal[:brief_path] ||= terminal.style(:yellow) terminal[:uncovered_prefix] ||= terminal.style(:red) terminal[:covered_prefix] ||= terminal.style(:green) terminal[:ignored_prefix] ||= terminal.style(nil, nil, :faint) terminal[:header_prefix] ||= terminal.style(nil, nil, :faint) terminal[:uncovered_code] ||= terminal.style(:red) terminal[:covered_code] ||= terminal.style(:green) terminal[:ignored_code] ||= terminal.style(nil, nil, :faint) terminal[:annotations] ||= terminal.style(:blue) end end