Module: SimpleCov::Combine::LinesCombiner

Defined in:
lib/simplecov/combine/lines_combiner.rb

Overview

Combine two different lines coverage results on same file

Should be called through ‘SimpleCov.combine`.

Class Method Summary collapse

Class Method Details

.combine(coverage_a, coverage_b) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/simplecov/combine/lines_combiner.rb', line 12

def combine(coverage_a, coverage_b)
  coverage_a
    .zip(coverage_b)
    .map do |coverage_a_val, coverage_b_val|
      merge_line_coverage(coverage_a_val, coverage_b_val)
    end
end

.merge_line_coverage(first_val, second_val) ⇒ Integer || nil

Return depends on coverage in a specific line

Logic:

> nil + 0 = nil

> nil + nil = nil

> int + int = int

Parameters:

  • first_val (Integer || nil)
  • second_val (Integer || nil)

Returns:

  • (Integer || nil)


32
33
34
35
36
37
38
39
40
# File 'lib/simplecov/combine/lines_combiner.rb', line 32

def merge_line_coverage(first_val, second_val)
  sum = first_val.to_i + second_val.to_i

  if sum.zero? && (first_val.nil? || second_val.nil?)
    nil
  else
    sum
  end
end