class Covered::Summary
def call(wrapper, output = $stdout)
def call(wrapper, output = $stdout) statistics = self.each(wrapper) do |coverage| line_offset = 1 path = wrapper.relative_path(coverage.path) output.puts "", Rainbow(path).bold.underline counts = coverage.counts coverage.read do |file| file.each_line do |line| count = counts[line_offset] print_annotations(output, coverage, line, line_offset) output.write("#{line_offset}|".rjust(8)) output.write("#{count}|".rjust(8)) if count == nil output.write Rainbow(line).faint elsif count == 0 output.write Rainbow(line).red else output.write Rainbow(line).green end # If there was no newline at end of file, we add one: unless line.end_with? $/ output.puts end line_offset += 1 end end coverage.print(output) end statistics.print(output) end
def each(wrapper)
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
def initialize(threshold: 1.0)
def initialize(threshold: 1.0) @threshold = threshold end
def print_annotations(output, coverage, line, line_offset)
def print_annotations(output, coverage, line, line_offset) if annotations = coverage.annotations[line_offset] output.write("#{line_offset}|".rjust(8)) output.write("*|".rjust(8)) output.write line.match(/^\s+/) output.write '# ' output.puts Rainbow(annotations.join(", ")).bright end end