123456789_123456789_123456789_123456789_123456789_

Module: SimpleCov::Combine::LinesCombiner

Relationships & Source Files
Defined in: lib/simplecov/combine/lines_combiner.rb

Overview

::SimpleCov::Combine two different lines coverage results on same file

Should be called through SimpleCov.combine.

Class Method Summary

Class Method Details

.combine(coverage_a, coverage_b) (mod_func)

[ GitHub ]

  
# 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 (mod_func)

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)
[ GitHub ]

  
# 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