Class: DeepCover::Analyser::StatsBase
- Inherits:
-
Object
- Object
- DeepCover::Analyser::StatsBase
- Includes:
- Memoize
- Defined in:
- lib/deep_cover/analyser/stats.rb
Direct Known Subclasses
Constant Summary collapse
- DECIMALS =
2
- VALUES =
All are exclusive
%i[executed not_executed not_executable ignored].freeze
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(executed: 0, not_executed: 0, not_executable: 0, ignored: 0) ⇒ StatsBase
constructor
A new instance of StatsBase.
- #percent_covered ⇒ Object
- #potentially_executable ⇒ Object
- #to_h ⇒ Object
- #total ⇒ Object
- #with(**values) ⇒ Object
Methods included from Memoize
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_covered ⇒ Object
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_executable ⇒ Object
37 38 39 |
# File 'lib/deep_cover/analyser/stats.rb', line 37 def potentially_executable total - not_executable end |
#to_h ⇒ Object
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 |
#total ⇒ Object
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 |