Class: SimpleCov::SourceFile::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/source_file/line.rb,
sig/simplecov.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, line_number, coverage) ⇒ Line

Returns a new instance of Line.

Parameters:

  • src (String)
  • line_number (Integer)
  • coverage (Integer, nil)

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/simplecov/source_file/line.rb', line 12

def initialize(src, line_number, coverage)
  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)
  unless coverage.is_a?(Integer) || coverage.nil?
    raise ArgumentError, "Only Integer and nil accepted for coverage"
  end

  @src = src
  @line_number = line_number
  @coverage = coverage
  @skipped = false
end

Instance Attribute Details

#coverageInteger? (readonly)

Returns the value of attribute coverage.

Returns:

  • (Integer, nil)


6
7
8
# File 'lib/simplecov/source_file/line.rb', line 6

def coverage
  @coverage
end

#line_numberInteger (readonly) Also known as: line, number

Returns the value of attribute line_number.

Returns:

  • (Integer)


6
7
8
# File 'lib/simplecov/source_file/line.rb', line 6

def line_number
  @line_number
end

#skippedBoolean (readonly)

Returns the value of attribute skipped.

Returns:

  • (Boolean)


6
7
8
# File 'lib/simplecov/source_file/line.rb', line 6

def skipped
  @skipped
end

#srcString (readonly) Also known as: source

Returns the value of attribute src.

Returns:

  • (String)


6
7
8
# File 'lib/simplecov/source_file/line.rb', line 6

def src
  @src
end

Instance Method Details

#covered?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/simplecov/source_file/line.rb', line 32

def covered?
  !skipped? && coverage.to_i.positive?
end

#missed?Boolean

Asking covered? rather than reading the count a second time keeps the two answers from ever disagreeing, and never? ahead of it is what keeps a line with no coverage at all out of the missed column.

Returns:

  • (Boolean)


28
29
30
# File 'lib/simplecov/source_file/line.rb', line 28

def missed?
  !never? && !skipped? && !covered?
end

#never?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/simplecov/source_file/line.rb', line 36

def never?
  !skipped? && coverage.nil?
end

#skipped!void

This method returns an undefined value.



40
41
42
# File 'lib/simplecov/source_file/line.rb', line 40

def skipped!
  @skipped = true
end

#skipped?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/simplecov/source_file/line.rb', line 44

def skipped?
  skipped
end

#statusString

Returns:

  • (String)


48
49
50
51
52
53
54
# File 'lib/simplecov/source_file/line.rb', line 48

def status
  return "skipped" if skipped?
  return "never" if never?
  return "missed" if missed?

  "covered"
end