Class: Coverband::Utils::SourceFile::Line
- Inherits:
-
Object
- Object
- Coverband::Utils::SourceFile::Line
- Defined in:
- lib/coverband/utils/source_file.rb
Overview
TODO: Refactor Line into its own file Representation of a single line in a source file including this specific line’s source code, line_number and code coverage, with the coverage being either nil (coverage not applicable, e.g. comment line), 0 (line not covered) or >1 (the amount of times the line was executed)
Instance Attribute Summary collapse
-
#coverage ⇒ Object
readonly
The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered).
-
#coverage_posted ⇒ Object
readonly
The coverage data posted time for this line: either nil (never), nil (missed) or Time instance (last posted).
-
#line_number ⇒ Object
(also: #line, #number)
readonly
The line number in the source file.
-
#skipped ⇒ Object
readonly
Whether this line was skipped.
-
#src ⇒ Object
(also: #source)
readonly
The source code for this line.
Instance Method Summary collapse
-
#covered? ⇒ Boolean
Returns true if this is a line that has been covered.
-
#initialize(src, line_number, coverage, coverage_posted = nil) ⇒ Line
constructor
A new instance of Line.
-
#missed? ⇒ Boolean
Returns true if this is a line that should have been covered, but was not.
-
#never? ⇒ Boolean
Returns true if this line is not relevant for coverage.
-
#skipped! ⇒ Object
Flags this line as skipped.
-
#skipped? ⇒ Boolean
Returns true if this line was skipped, false otherwise.
-
#status ⇒ Object
The status of this line - either covered, missed, skipped or never.
Constructor Details
#initialize(src, line_number, coverage, coverage_posted = nil) ⇒ Line
Returns a new instance of Line.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/coverband/utils/source_file.rb', line 36 def initialize(src, line_number, coverage, coverage_posted = nil) raise ArgumentError, "Only String accepted for source" unless src.is_a?(String) raise ArgumentError, "Only Integer accepted for line_number" unless line_number.is_a?(Integer) raise ArgumentError, "Only Integer and nil accepted for coverage" unless coverage.is_a?(Integer) || coverage.nil? @src = src @line_number = line_number @coverage = coverage @skipped = false @coverage_posted = coverage_posted end |
Instance Attribute Details
#coverage ⇒ Object (readonly)
The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered)
25 26 27 |
# File 'lib/coverband/utils/source_file.rb', line 25 def coverage @coverage end |
#coverage_posted ⇒ Object (readonly)
The coverage data posted time for this line: either nil (never), nil (missed) or Time instance (last posted)
29 30 31 |
# File 'lib/coverband/utils/source_file.rb', line 29 def coverage_posted @coverage_posted end |
#line_number ⇒ Object (readonly) Also known as: line, number
The line number in the source file. Aliased as :line, :number
23 24 25 |
# File 'lib/coverband/utils/source_file.rb', line 23 def line_number @line_number end |
#skipped ⇒ Object (readonly)
Whether this line was skipped
27 28 29 |
# File 'lib/coverband/utils/source_file.rb', line 27 def skipped @skipped end |
#src ⇒ Object (readonly) Also known as: source
The source code for this line. Aliased as :source
21 22 23 |
# File 'lib/coverband/utils/source_file.rb', line 21 def src @src end |
Instance Method Details
#covered? ⇒ Boolean
Returns true if this is a line that has been covered
54 55 56 |
# File 'lib/coverband/utils/source_file.rb', line 54 def covered? !never? && !skipped? && coverage.positive? end |
#missed? ⇒ Boolean
Returns true if this is a line that should have been covered, but was not
49 50 51 |
# File 'lib/coverband/utils/source_file.rb', line 49 def missed? !never? && !skipped? && coverage.zero? end |
#never? ⇒ Boolean
Returns true if this line is not relevant for coverage
59 60 61 |
# File 'lib/coverband/utils/source_file.rb', line 59 def never? !skipped? && coverage.nil? end |
#skipped! ⇒ Object
Flags this line as skipped
64 65 66 |
# File 'lib/coverband/utils/source_file.rb', line 64 def skipped! @skipped = true end |
#skipped? ⇒ Boolean
Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with # :nocov: comment lines.
70 71 72 |
# File 'lib/coverband/utils/source_file.rb', line 70 def skipped? skipped end |
#status ⇒ Object
The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use as a css class in report generation
76 77 78 79 80 81 |
# File 'lib/coverband/utils/source_file.rb', line 76 def status return "skipped" if skipped? return "never" if never? return "missed" if missed? "covered" if covered? end |