Class: Rivulet::SumWindow
Instance Method Summary collapse
- #add(value) ⇒ Object
- #average ⇒ Object
- #evict ⇒ Object
-
#initialize ⇒ SumWindow
constructor
A new instance of SumWindow.
- #sum ⇒ Object
Methods inherited from Window
Constructor Details
#initialize ⇒ SumWindow
Returns a new instance of SumWindow.
5 6 7 8 9 10 |
# File 'lib/rivulet/sum_window.rb', line 5 def initialize super @sum = 0 @items = [] @front = 0 end |
Instance Method Details
#add(value) ⇒ Object
12 13 14 15 16 |
# File 'lib/rivulet/sum_window.rb', line 12 def add(value) @sum += value @items.push(value) super end |
#average ⇒ Object
28 29 30 |
# File 'lib/rivulet/sum_window.rb', line 28 def average @sum.fdiv(size) unless empty? end |
#evict ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rivulet/sum_window.rb', line 18 def evict if @front < @items.size @sum -= @items[@front] @front += 1 end super end |
#sum ⇒ Object
26 |
# File 'lib/rivulet/sum_window.rb', line 26 def sum = @sum |