Class: Fin::Book

Inherits:
ContainerList show all
Defined in:
lib/fin/book.rb

Overview

Represents a Book (QuoteBook, DealBook, etc…) - collection of all items associated with one security(isin) It is used as additional index by ContainerList subclasses (QuoteList, DealList)

Instance Attribute Summary collapse

Attributes inherited from ContainerList

#item_type

Attributes inherited from ChangedList

#change_count, #changed, #updated

Instance Method Summary collapse

Methods inherited from ContainerList

#add_message, #add_record, #remove_message, #remove_record

Methods inherited from ChangedList

#update_noted

Constructor Details

#initialize(opts = {}) ⇒ Book

Returns a new instance of Book.



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

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

Instance Attribute Details

#isin_idObject (readonly) Also known as: isin

Returns the value of attribute isin_id.



9
10
11
# File 'lib/fin/book.rb', line 9

def isin_id
  @isin_id
end

Instance Method Details

#add?(item) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/fin/book.rb', line 37

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

#check(item) ⇒ Object

Validation of the item being included



21
22
23
24
25
26
27
# File 'lib/fin/book.rb', line 21

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

#index(item) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fin/book.rb', line 29

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

#remove?(item) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/fin/book.rb', line 44

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