Class: SimpleCov::SourceFile::Branch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch

Returns a new instance of Branch.

Parameters:

  • start_line: (Integer)
  • end_line: (Integer)
  • coverage: (Integer)
  • inline: (Boolean)
  • type: (Symbol)


8
9
10
11
12
13
14
15
# File 'lib/simplecov/source_file/branch.rb', line 8

def initialize(start_line:, end_line:, coverage:, inline:, type:)
  @start_line = start_line
  @end_line = end_line
  @coverage = coverage
  @inline = inline
  @type = type
  @skipped = false
end

Instance Attribute Details

#coverageInteger (readonly)

Returns the value of attribute coverage.

Returns:

  • (Integer)


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

def coverage
  @coverage
end

#end_lineInteger (readonly)

Returns the value of attribute end_line.

Returns:

  • (Integer)


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

def end_line
  @end_line
end

#start_lineInteger (readonly)

Returns the value of attribute start_line.

Returns:

  • (Integer)


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

def start_line
  @start_line
end

#typeSymbol (readonly)

Returns the value of attribute type.

Returns:

  • (Symbol)


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

def type
  @type
end

Instance Method Details

#covered?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/simplecov/source_file/branch.rb', line 21

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

#inline?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/simplecov/source_file/branch.rb', line 17

def inline?
  @inline
end

#missed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/simplecov/source_file/branch.rb', line 25

def missed?
  !skipped? && coverage.zero?
end

#overlaps_with?(line_range) ⇒ Boolean

Parameters:

  • line_range (Range[Integer])

Returns:

  • (Boolean)


48
49
50
# File 'lib/simplecov/source_file/branch.rb', line 48

def overlaps_with?(line_range)
  start_line <= line_range.end && end_line >= line_range.begin
end

#report[ Symbol, Integer ]

Returns:

  • ([ Symbol, Integer ])


52
53
54
# File 'lib/simplecov/source_file/branch.rb', line 52

def report
  [type, coverage]
end

#report_lineInteger

Usually the line above the start of the branch, so that it shows up at the if/else. That highlights the condition, and makes it distinguishable when the first line of the branch is itself an inline branch.

Returns:

  • (Integer)


32
33
34
35
36
37
38
# File 'lib/simplecov/source_file/branch.rb', line 32

def report_line
  if inline?
    start_line
  else
    start_line - 1
  end
end

#skipped!void

This method returns an undefined value.



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

def skipped!
  @skipped = true
end

#skipped?Boolean

Returns:

  • (Boolean)


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

def skipped?
  @skipped
end