Class: R19Cov::Coverage
- Inherits:
-
Object
- Object
- R19Cov::Coverage
- Defined in:
- lib/r19cov.rb,
lib/r19cov/coverage.rb,
lib/r19cov/coverage/summary.rb
Defined Under Namespace
Classes: Summary
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #code_coverage ⇒ Object
- #covered ⇒ Object
-
#initialize(source_file, result) ⇒ Coverage
constructor
A new instance of Coverage.
- #lines_of_code ⇒ Object
- #load_source_file(source_file) ⇒ Object
- #total_coverage ⇒ Object
- #total_lines ⇒ Object
- #uncovered ⇒ Object
Constructor Details
#initialize(source_file, result) ⇒ Coverage
Returns a new instance of Coverage.
5 6 7 8 9 |
# File 'lib/r19cov/coverage.rb', line 5 def initialize(source_file, result) @filename = source_file @result = result load_source_file(source_file) end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/r19cov/coverage.rb', line 11 def filename @filename end |
#lines ⇒ Object
Returns the value of attribute lines.
11 12 13 |
# File 'lib/r19cov/coverage.rb', line 11 def lines @lines end |
#result ⇒ Object
Returns the value of attribute result.
11 12 13 |
# File 'lib/r19cov/coverage.rb', line 11 def result @result end |
Instance Method Details
#code_coverage ⇒ Object
29 30 31 |
# File 'lib/r19cov/coverage.rb', line 29 def code_coverage lines_of_code > 0 ? covered.to_f / lines_of_code.to_f : 0.0 end |
#covered ⇒ Object
37 38 39 |
# File 'lib/r19cov/coverage.rb', line 37 def covered result.select{ |c| !c.nil? && c > 0 }.size end |
#lines_of_code ⇒ Object
21 22 23 |
# File 'lib/r19cov/coverage.rb', line 21 def lines_of_code result.select{ |c| !c.nil? }.size end |
#load_source_file(source_file) ⇒ Object
13 14 15 |
# File 'lib/r19cov/coverage.rb', line 13 def load_source_file(source_file) @lines = File.read(source_file).split("\n") end |
#total_coverage ⇒ Object
25 26 27 |
# File 'lib/r19cov/coverage.rb', line 25 def total_coverage total_lines > 0 ? (total_lines.to_f - uncovered.to_f) / total_lines.to_f : 0.0 end |
#total_lines ⇒ Object
17 18 19 |
# File 'lib/r19cov/coverage.rb', line 17 def total_lines lines.size end |
#uncovered ⇒ Object
33 34 35 |
# File 'lib/r19cov/coverage.rb', line 33 def uncovered result.select{ |c| c == 0 }.size end |