Module: TeaLeaves::ArrayMethods

Defined in:
lib/tealeaves/moving_average.rb

Instance Method Summary collapse

Instance Method Details

#moving_average(average_specifier) ⇒ Object

Returns a moving average for this array, given either a number of terms or a list of weights.

See MovingAverage for more detail.



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/tealeaves/moving_average.rb', line 96

def moving_average(average_specifier)
  if average_specifier.kind_of?(Array)
    avg = MovingAverage.weighted(average_specifier)
  elsif average_specifier.kind_of?(Integer)
    avg = MovingAverage.simple(average_specifier)
  else
    raise ArgumentError.new("Unknown weights")
  end
  
  avg.calculate(self)
end