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
print_line(terminal, line, line_offset, count) click to toggle source
print_line_header(terminal) click to toggle source
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