Class: Coco::CoverageStat
- Inherits:
-
Object
- Object
- Coco::CoverageStat
- Defined in:
- lib/coco/cover/coverage_stat.rb
Overview
Give statistics about an array of lines hit.
An “array of lines hit” is an array of integers, possibly nil. Such array is obtain from Coverage.result.
Each integer represent the state of a source line:
-
nil: source line will never be reached (like comments)
-
0: source line could be reached, but was not
-
1 and above: number of time the source line has been reached
Class Method Summary collapse
- .coverage_percent(hits) ⇒ Object
- .number_of_covered_lines(hits) ⇒ Object
- .remove_nil_from(hits) ⇒ Object
Class Method Details
.coverage_percent(hits) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/coco/cover/coverage_stat.rb', line 24 def CoverageStat.coverage_percent hits hits = CoverageStat.remove_nil_from hits return 0 if hits.empty? one_percent = 100.0 / hits.size (CoverageStat.number_of_covered_lines(hits) * one_percent).to_i end |
.number_of_covered_lines(hits) ⇒ Object
20 21 22 |
# File 'lib/coco/cover/coverage_stat.rb', line 20 def CoverageStat.number_of_covered_lines hits hits.select {|elem| elem > 0}.size end |
.remove_nil_from(hits) ⇒ Object
16 17 18 |
# File 'lib/coco/cover/coverage_stat.rb', line 16 def CoverageStat.remove_nil_from hits hits.select {|elem| not elem.nil?} end |