Module: Fin::BookManager

Included in:
DealList, QuoteList
Defined in:
lib/fin/book_manager.rb

Overview

Adds to including List a set of @books, each related to a single security(isin). its items, grouped by item’s isin_id. For example: QuoteBook, DealBook

Instance Method Summary collapse

Instance Method Details

#add?(item) ⇒ Boolean

Overwrites/removes existing item with the same index

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
# File 'lib/fin/book_manager.rb', line 23

def add? item
  if check item
    old_item = self[index item]
    remove old_item if old_item # Remove old item with the same index(id)
    if super
      books[item.isin_id].add item # Add item to appropriate order book
      item
    end
  end
end

#booksObject



12
13
14
15
16
17
18
19
20
# File 'lib/fin/book_manager.rb', line 12

def books
  @books ||= Hash.new do |hash, key|
    hash[key] = Book.new :isin_id => key,
                         :item_type => @item_type,
                         :book_index => @book_index,
                         :book_condition => @book_condition
    hash[key]
  end
end

#remove?(item) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/fin/book_manager.rb', line 34

def remove? item
  if super
    # Removing item from appropriate order book when it's deleted from order list
    books[item.isin_id].remove item
    item
  end
end