Class: Moneymarket::Slope
- Inherits:
-
Object
- Object
- Moneymarket::Slope
- Defined in:
- lib/moneymarket/core/slope.rb
Instance Method Summary collapse
- #add(_order) ⇒ Object
- #each ⇒ Object
- #each_until_limit(_limit) ⇒ Object
-
#initialize(&_comp_func) ⇒ Slope
constructor
A new instance of Slope.
- #remove(_order) ⇒ Object
Constructor Details
#initialize(&_comp_func) ⇒ Slope
Returns a new instance of Slope.
3 4 5 6 |
# File 'lib/moneymarket/core/slope.rb', line 3 def initialize(&_comp_func) @orders = [] @cmp = _comp_func end |
Instance Method Details
#add(_order) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/moneymarket/core/slope.rb', line 8 def add(_order) idx = orders.index { |o| compare(o, _order) > 0 } if idx.nil? orders << _order else orders.insert idx, _order end end |
#each ⇒ Object
21 22 23 |
# File 'lib/moneymarket/core/slope.rb', line 21 def each orders.each end |
#each_until_limit(_limit) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/moneymarket/core/slope.rb', line 25 def each_until_limit(_limit) Enumerator.new do |y| orders.each do |order| break if cmp.call(order, _limit) > 0 y << order end end end |
#remove(_order) ⇒ Object
17 18 19 |
# File 'lib/moneymarket/core/slope.rb', line 17 def remove(_order) orders.delete(_order) end |