Class: Nosey::Probe::Average

Inherits:
Base
  • Object
show all
Defined in:
lib/nosey/probe.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#set, #to_hash

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

#resetObject



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

#valueObject



40
41
42
# File 'lib/nosey/probe.rb', line 40

def value
  @sum.to_f / @count.to_f if @sum and @count > 0
end