Sha256: 0d00e0f9408d0a0304322af3570ca583ab9e18805032983fcf33ebdd5a611cfb

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'fin/container_list'

module Fin
  # Represents Book (OrderBook, DealBook, etc...) for one security(isin)
  # It is used as additional index by BookedList subclass (OrderList, DealList)
  class Book < ContainerList

    attr_reader :isin_id
    alias isin isin_id

    def initialize opts = {}
      @isin_id = opts[:isin_id]
      @book_index = opts[:book_index]
      @book_condition = opts[:book_condition]
      raise "No isin_id given for #{self}" unless @isin_id
      super
    end

    # Validation of the item being included
    def check item
      if item.is_a?(@item_type) && item.isin_id == isin_id
        @book_condition ? @book_condition.call(item) : true
      else
        false
      end
    end

    def index item
      if @book_index
        @book_index.call(item)
      else
        super
      end
    end

    def add? item
      if super
        item.book = self
        item
      end
    end

    def remove? item
      if super
        item.book = nil
        item
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fin-0.1.0 lib/fin/book.rb