class Tailstrom::Counter

Public Class Methods

new() click to toggle source
# File lib/tailstrom/counter.rb, line 3
def initialize
  clear
end

Public Instance Methods

<<(value) click to toggle source
# File lib/tailstrom/counter.rb, line 7
def <<(value)
  purge_cache
  @values << value
end
avg() click to toggle source
# File lib/tailstrom/counter.rb, line 21
def avg
  return nil if @values.empty?
  sum / @values.length
end
clear() click to toggle source
# File lib/tailstrom/counter.rb, line 12
def clear
  @values = []
  purge_cache
end
count() click to toggle source
# File lib/tailstrom/counter.rb, line 42
def count
  @cache[:count] ||= @values.count
end
max() click to toggle source
# File lib/tailstrom/counter.rb, line 34
def max
  @cache[:max] ||= @values.max
end
med() click to toggle source
# File lib/tailstrom/counter.rb, line 38
def med
  @values[@values.length / 2]
end
min() click to toggle source
# File lib/tailstrom/counter.rb, line 30
def min
  @cache[:min] ||= @values.min
end
purge_cache() click to toggle source
# File lib/tailstrom/counter.rb, line 17
def purge_cache
  @cache = {}
end
sum() click to toggle source
# File lib/tailstrom/counter.rb, line 26
def sum
  @cache[:sum] ||= @values.inject(0, :+)
end