class Moneymarket::Slope

Attributes

cmp[R]
orders[R]

Public Class Methods

new(&_comp_func) click to toggle source
# File lib/moneymarket/core/slope.rb, line 3
def initialize(&_comp_func)
  @orders = []
  @cmp = _comp_func
end

Public Instance Methods

add(_order) click to toggle source
# 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() click to toggle source
# File lib/moneymarket/core/slope.rb, line 21
def each
  orders.each
end
each_until_limit(_limit) click to toggle source
# 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) click to toggle source
# File lib/moneymarket/core/slope.rb, line 17
def remove(_order)
  orders.delete(_order)
end

Private Instance Methods

compare(a, b) click to toggle source
# File lib/moneymarket/core/slope.rb, line 38
def compare(a, b)
  r = cmp.call a, b
  r = a.created_at <=> b.created_at if r == 0
  r
end