Class: DeepCover::Analyser::StatsBase

Inherits:
Object
  • Object
show all
Includes:
Memoize
Defined in:
lib/deep_cover/analyser/stats.rb

Direct Known Subclasses

Stats

Constant Summary collapse

DECIMALS =
2
VALUES =

All are exclusive

%i[executed not_executed not_executable ignored].freeze

Instance Method Summary collapse

Methods included from Memoize

#freeze, included

Constructor Details

#initialize(executed: 0, not_executed: 0, not_executable: 0, ignored: 0) ⇒ StatsBase

Returns a new instance of StatsBase.



17
18
19
20
21
22
23
# File 'lib/deep_cover/analyser/stats.rb', line 17

def initialize(executed: 0, not_executed: 0, not_executable: 0, ignored: 0)
  @executed = executed
  @not_executed = not_executed
  @not_executable = not_executable
  @ignored = ignored
  freeze
end

Instance Method Details

#+(other) ⇒ Object



25
26
27
# File 'lib/deep_cover/analyser/stats.rb', line 25

def +(other)
  self.class.new(to_h.merge(other.to_h) { |k, a, b| a + b })
end

#percent_coveredObject



41
42
43
44
# File 'lib/deep_cover/analyser/stats.rb', line 41

def percent_covered
  return 100 if potentially_executable == 0
  (100 * (1 - not_executed.fdiv(potentially_executable))).round(DECIMALS)
end

#potentially_executableObject



37
38
39
# File 'lib/deep_cover/analyser/stats.rb', line 37

def potentially_executable
  total - not_executable
end

#to_hObject



13
14
15
# File 'lib/deep_cover/analyser/stats.rb', line 13

def to_h
  VALUES.map { |val| [val, public_send(val)] }.to_h
end

#totalObject



29
30
31
# File 'lib/deep_cover/analyser/stats.rb', line 29

def total
  to_h.values.inject(:+)
end

#with(**values) ⇒ Object



33
34
35
# File 'lib/deep_cover/analyser/stats.rb', line 33

def with(**values)
  self.class.new(to_h.merge(values))
end