Class: SimpleCov::ResultAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/result_adapter.rb

Overview

Responsible for adapting the format of the coverage result whether it’s default or with statistics

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ ResultAdapter

Returns a new instance of ResultAdapter.



10
11
12
# File 'lib/simplecov/result_adapter.rb', line 10

def initialize(result)
  @result = result
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/simplecov/result_adapter.rb', line 8

def result
  @result
end

Class Method Details

.call(*args) ⇒ Object



14
15
16
# File 'lib/simplecov/result_adapter.rb', line 14

def self.call(*args)
  new(*args).adapt
end

Instance Method Details

#adaptObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simplecov/result_adapter.rb', line 18

def adapt
  return unless result

  result.each_with_object({}) do |(file_name, cover_statistic), adapted_result|
    if cover_statistic.is_a?(Array)
      adapted_result.merge!(file_name => {"lines" => cover_statistic})
    else
      adapted_result.merge!(file_name => cover_statistic)
    end
  end
end