Class: SolargraphTestCoverage::Branch
- Inherits:
-
Object
- Object
- SolargraphTestCoverage::Branch
- Defined in:
- lib/solargraph_test_coverage/branch.rb
Overview
Adapted from SimpleCov - Small class that turns branch coverage data into something easier to work with
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.
Class Method Summary collapse
Instance Method Summary collapse
- #covered? ⇒ Boolean
-
#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch
constructor
A new instance of Branch.
- #inline? ⇒ Boolean
- #report ⇒ Object
- #report_line ⇒ Object
Constructor Details
#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch
Returns a new instance of Branch.
21 22 23 24 25 26 27 |
# File 'lib/solargraph_test_coverage/branch.rb', line 21 def initialize(start_line:, end_line:, coverage:, inline:, type:) @start_line = start_line @end_line = end_line @coverage = coverage @inline = inline @type = type end |
Instance Attribute Details
#coverage ⇒ Object (readonly)
Returns the value of attribute coverage.
19 20 21 |
# File 'lib/solargraph_test_coverage/branch.rb', line 19 def coverage @coverage end |
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
19 20 21 |
# File 'lib/solargraph_test_coverage/branch.rb', line 19 def end_line @end_line end |
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
19 20 21 |
# File 'lib/solargraph_test_coverage/branch.rb', line 19 def start_line @start_line end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/solargraph_test_coverage/branch.rb', line 19 def type @type end |
Class Method Details
.build_from(results) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/solargraph_test_coverage/branch.rb', line 6 def self.build_from(results) results.fetch(:branches, {}).flat_map do |condition, branches| _condition_type, _condition_id, condition_start_line, * = condition branches.map do |branch_data, hit_count| type, _id, start_line, _start_col, end_line, _end_col = branch_data new(start_line: start_line, end_line: end_line, coverage: hit_count, inline: start_line == condition_start_line, type: type) end end end |
Instance Method Details
#covered? ⇒ Boolean
33 34 35 |
# File 'lib/solargraph_test_coverage/branch.rb', line 33 def covered? coverage.positive? end |
#inline? ⇒ Boolean
29 30 31 |
# File 'lib/solargraph_test_coverage/branch.rb', line 29 def inline? @inline end |
#report ⇒ Object
41 42 43 |
# File 'lib/solargraph_test_coverage/branch.rb', line 41 def report { type: type, line: report_line } end |
#report_line ⇒ Object
37 38 39 |
# File 'lib/solargraph_test_coverage/branch.rb', line 37 def report_line inline? ? start_line : start_line - 1 end |