Class: Wildsight::Metrics::Statistics
- Inherits:
-
Object
- Object
- Wildsight::Metrics::Statistics
- Defined in:
- lib/wildsight/metrics/statistics.rb
Instance Method Summary collapse
- #add(value = 0) ⇒ Object
-
#initialize(values = []) ⇒ Statistics
constructor
A new instance of Statistics.
- #reset(values = []) ⇒ Object
Constructor Details
#initialize(values = []) ⇒ Statistics
Returns a new instance of Statistics.
6 7 8 |
# File 'lib/wildsight/metrics/statistics.rb', line 6 def initialize(values = []) reset(values) end |
Instance Method Details
#add(value = 0) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/wildsight/metrics/statistics.rb', line 10 def add(value = 0) @values[:max] = values if @values[:max] == nil || @values[:max] < values @values[:min] = values if @values[:min] == nil || @values[:min] > values @values[:sum] += value @values[:cnt] += 1 end |
#reset(values = []) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/wildsight/metrics/statistics.rb', line 17 def reset(values = []) @values = { max: nil, min: nil, sum: 0, cnt: 0 } values.each { |value| add(value) } end |