Class: Nosey::Probe::Average
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(*args) ⇒ Average
constructor
A new instance of Average.
- #reset ⇒ Object
- #sample(value) ⇒ Object
- #value ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Average
Returns a new instance of Average.
30 31 32 33 |
# File 'lib/nosey/probe.rb', line 30 def initialize(*args) super(*args) reset end |
Instance Method Details
#reset ⇒ Object
44 45 46 47 48 |
# File 'lib/nosey/probe.rb', line 44 def reset @sum = 0 @count = 0 @count = 0 end |
#sample(value) ⇒ Object
35 36 37 38 |
# File 'lib/nosey/probe.rb', line 35 def sample(value) @sum += value @count += 1 end |
#value ⇒ Object
40 41 42 |
# File 'lib/nosey/probe.rb', line 40 def value @sum.to_f / @count.to_f if @sum and @count > 0 end |