Class: SimpleCov::SourceFile::Branch
- Inherits:
 - 
      Object
      
        
- Object
 - SimpleCov::SourceFile::Branch
 
 
- Defined in:
 - lib/simplecov/source_file/branch.rb
 
Overview
Representing single branch that has been detected in coverage report. Give us support methods that handle needed calculations.
Instance Attribute Summary collapse
- 
  
    
      #coverage  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute coverage.
 - 
  
    
      #end_line  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute end_line.
 - 
  
    
      #start_line  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute start_line.
 - 
  
    
      #type  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute type.
 
Instance Method Summary collapse
- 
  
    
      #covered?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Return true if there is relevant count defined > 0.
 - 
  
    
      #initialize(start_line:, end_line:, coverage:, inline:, type:)  ⇒ Branch 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
rubocop:disable Metrics/ParameterLists.
 - 
  
    
      #inline?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
rubocop:enable Metrics/ParameterLists.
 - 
  
    
      #missed?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check if branche missed or not.
 - #overlaps_with?(line_range) ⇒ Boolean
 - 
  
    
      #report  ⇒ Array 
    
    
  
  
  
  
  
  
  
  
  
    
Return array with coverage count and badge.
 - 
  
    
      #report_line  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
The line on which we want to report the coverage.
 - 
  
    
      #skipped!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Flags the branch as skipped.
 - 
  
    
      #skipped?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if the branch was marked skipped by virtue of nocov comments.
 
Constructor Details
#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch
rubocop:disable Metrics/ParameterLists
      12 13 14 15 16 17 18 19  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 12 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
#coverage ⇒ Object (readonly)
Returns the value of attribute coverage.
      9 10 11  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 9 def coverage @coverage end  | 
  
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
      9 10 11  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 9 def end_line @end_line end  | 
  
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
      9 10 11  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 9 def start_line @start_line end  | 
  
#type ⇒ Object (readonly)
Returns the value of attribute type.
      9 10 11  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 9 def type @type end  | 
  
Instance Method Details
#covered? ⇒ Boolean
Return true if there is relevant count defined > 0
      31 32 33  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 31 def covered? !skipped? && coverage.positive? end  | 
  
#inline? ⇒ Boolean
rubocop:enable Metrics/ParameterLists
      22 23 24  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 22 def inline? @inline end  | 
  
#missed? ⇒ Boolean
Check if branche missed or not
      40 41 42  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 40 def missed? !skipped? && coverage.zero? end  | 
  
#overlaps_with?(line_range) ⇒ Boolean
      70 71 72  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 70 def overlaps_with?(line_range) start_line <= line_range.end && end_line >= line_range.begin end  | 
  
#report ⇒ Array
Return array with coverage count and badge
      79 80 81  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 79 def report [type, coverage] end  | 
  
#report_line ⇒ Object
The line on which we want to report the coverage
Usually we choose the line above the start of the branch (so that it shows up at if/else) because that
- 
highlights the condition
 - 
makes it distinguishable if the first line of the branch is an inline branch (see the nested_branches fixture)
 
      52 53 54 55 56 57 58  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 52 def report_line if inline? start_line else start_line - 1 end end  | 
  
#skipped! ⇒ Object
Flags the branch as skipped
      61 62 63  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 61 def skipped! @skipped = true end  | 
  
#skipped? ⇒ Boolean
Returns true if the branch was marked skipped by virtue of nocov comments.
      66 67 68  | 
    
      # File 'lib/simplecov/source_file/branch.rb', line 66 def skipped? @skipped end  |