Class: SimpleCov::LinesClassifier
- Inherits:
-
Object
- Object
- SimpleCov::LinesClassifier
- Defined in:
- lib/simplecov/lines_classifier.rb
Overview
Classifies whether lines are relevant for code coverage analysis. Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.
Constant Summary collapse
- RELEVANT =
0- NOT_RELEVANT =
nil- WHITESPACE_LINE =
/^\s*$/- COMMENT_LINE =
/^\s*#/- WHITESPACE_OR_COMMENT_LINE =
Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.no_cov_line ⇒ Object
17 18 19 |
# File 'lib/simplecov/lines_classifier.rb', line 17 def self.no_cov_line /^(\s*)#(\s*)(:#{SimpleCov.current_nocov_token}:)/o end |
.no_cov_line?(line) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/simplecov/lines_classifier.rb', line 21 def self.no_cov_line?(line) no_cov_line.match?(line) rescue ArgumentError # E.g., line contains an invalid byte sequence in UTF-8 false end |
.whitespace_line?(line) ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/simplecov/lines_classifier.rb', line 28 def self.whitespace_line?(line) WHITESPACE_OR_COMMENT_LINE.match?(line) rescue ArgumentError # E.g., line contains an invalid byte sequence in UTF-8 false end |
Instance Method Details
#classify(lines) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/simplecov/lines_classifier.rb', line 35 def classify(lines) lines = lines.to_a directive_disabled = directive_disabled_line_set(lines) skipping = false lines.map.with_index(1) do |line, line_number| skipping = !skipping if self.class.no_cov_line?(line) not_relevant_line?(line, line_number, skipping, directive_disabled) ? NOT_RELEVANT : RELEVANT end end |