Class: Coverband::Utils::LinesClassifier

Inherits:
Object
  • Object
show all
Defined in:
lib/coverband/utils/lines_classifier.rb

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_lineObject



25
26
27
# File 'lib/coverband/utils/lines_classifier.rb', line 25

def self.no_cov_line
  /^(\s*)#(\s*)(\:nocov\:)/o
end

.no_cov_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/coverband/utils/lines_classifier.rb', line 29

def self.no_cov_line?(line)
  line =~ no_cov_line
rescue ArgumentError
  # E.g., line contains an invalid byte sequence in UTF-8
  false
end

.whitespace_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/coverband/utils/lines_classifier.rb', line 36

def self.whitespace_line?(line)
  line =~ WHITESPACE_OR_COMMENT_LINE
rescue ArgumentError
  # E.g., line contains an invalid byte sequence in UTF-8
  false
end

Instance Method Details

#classify(lines) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/coverband/utils/lines_classifier.rb', line 43

def classify(lines)
  skipping = false

  lines.map do |line|
    if self.class.no_cov_line?(line)
      skipping = !skipping
      NOT_RELEVANT
    elsif skipping || self.class.whitespace_line?(line)
      NOT_RELEVANT
    else
      RELEVANT
    end
  end
end