Class: Covered::MarkdownSummary
- Inherits:
-
Object
- Object
- Covered::MarkdownSummary
- Defined in:
- lib/covered/markdown_summary.rb
Instance Method Summary collapse
-
#call(wrapper, output = $stdout) ⇒ Object
A coverage array gives, for each line, the number of line execution by the interpreter.
- #each(wrapper) ⇒ Object
-
#initialize(threshold: 1.0) ⇒ MarkdownSummary
constructor
A new instance of MarkdownSummary.
- #print_annotations(output, coverage, line, line_offset) ⇒ Object
- #print_line(output, line, line_offset, count) ⇒ Object
- #print_line_header(output) ⇒ Object
Constructor Details
#initialize(threshold: 1.0) ⇒ MarkdownSummary
Returns a new instance of MarkdownSummary.
28 29 30 |
# File 'lib/covered/markdown_summary.rb', line 28 def initialize(threshold: 1.0) @threshold = threshold end |
Instance Method Details
#call(wrapper, output = $stdout) ⇒ Object
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).
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/covered/markdown_summary.rb', line 73 def call(wrapper, output = $stdout) output.puts '# Coverage Report' output.puts ordered = [] buffer = StringIO.new statistics = self.each(wrapper) do |coverage| ordered << coverage unless coverage.complete? end statistics.print(output) if ordered.any? output.puts "", "\#\# Least Coverage:", "" ordered.sort_by!(&:missing_count).reverse! ordered.first(5).each do |coverage| path = wrapper.relative_path(coverage.path) output.puts "- `#{path}`: #{coverage.missing_count} lines not executed!" end end output.print(buffer.string) end |
#each(wrapper) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/covered/markdown_summary.rb', line 32 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(output, coverage, line, line_offset) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/covered/markdown_summary.rb', line 46 def print_annotations(output, coverage, line, line_offset) if annotations = coverage.annotations[line_offset] prefix = "#{line_offset}|".rjust(8) + "*|".rjust(8) output.write prefix output.write line.match(/^\s+/) output.puts "\# #{annotations.join(", ")}" end end |
#print_line(output, line, line_offset, count) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/covered/markdown_summary.rb', line 60 def print_line(output, line, line_offset, count) prefix = "#{line_offset}|".rjust(8) + "#{count}|".rjust(8) output.write prefix output.write line # If there was no newline at end of file, we add one: unless line.end_with?($/) output.puts end end |
#print_line_header(output) ⇒ Object
56 57 58 |
# File 'lib/covered/markdown_summary.rb', line 56 def print_line_header(output) output.puts "Line|".rjust(8) + "Hits|".rjust(8) end |