Class: Covered::PartialSummary
- Defined in:
- lib/covered/summary.rb
Instance Attribute Summary
Attributes inherited from Wrapper
Instance Method Summary collapse
Methods inherited from Summary
#each, #initialize, #print_annotations
Methods inherited from Wrapper
#disable, #each, #enable, #initialize, #mark, #to_h
Constructor Details
This class inherits a constructor from Covered::Summary
Instance Method Details
#print_summary(output = $stdout, before: 4, after: 4) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/covered/summary.rb', line 125 def print_summary(output = $stdout, before: 4, after: 4) statistics = self.each do |coverage| line_offset = 1 output.puts "", Rainbow(coverage.path).bold.underline counts = coverage.counts last_line = nil unless coverage.zero? File.open(coverage.path, "r") do |file| file.each_line do |line| range = Range.new([line_offset - before, 0].max, line_offset+after) if counts[range]&.include?(0) count = counts[line_offset] if last_line and last_line != line_offset-1 output.puts ":".rjust(16) end print_annotations(output, coverage, line, line_offset) prefix = "#{line_offset}|".rjust(8) + "#{count}|".rjust(8) if count == nil output.write prefix output.write Rainbow(line).faint elsif count == 0 output.write Rainbow(prefix).background(:darkred) output.write Rainbow(line).red else output.write Rainbow(prefix).background(:darkgreen) 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 last_line = line_offset end line_offset += 1 end end end coverage.print_summary(output) end output.puts statistics.print_summary(output) end |