Class: Moneymarket::Slope

Inherits:
Object
  • Object
show all
Defined in:
lib/moneymarket/core/slope.rb

Instance Method Summary collapse

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

#eachObject



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