Class: Fin::ContainerList

Inherits:
ChangedList show all
Defined in:
lib/fin/container_list.rb

Overview

Represents Container that holds Model objects (items) of only ONE specific type TODO: In future, merge ChangedList and ContainerList to flatten class hierarchy

Direct Known Subclasses

Book, DealList, QuoteList

Instance Attribute Summary collapse

Attributes inherited from ChangedList

#change_count, #changed, #updated

Instance Method Summary collapse

Methods inherited from ChangedList

#add?, #remove?, #update_noted

Constructor Details

#initialize(opts = {}) ⇒ ContainerList

Returns a new instance of ContainerList.



10
11
12
13
14
# File 'lib/fin/container_list.rb', line 10

def initialize opts = {}
  @item_type = opts[:item_type]
  raise "Item type not given for #{self}" unless @item_type
  super()
end

Instance Attribute Details

#item_typeObject (readonly)

Returns the value of attribute item_type.



8
9
10
# File 'lib/fin/container_list.rb', line 8

def item_type
  @item_type
end

Instance Method Details

#add_message(msg) ⇒ Object



33
34
35
# File 'lib/fin/container_list.rb', line 33

def add_message msg
  add? @item_type.from_msg msg
end

#add_record(rec) ⇒ Object



24
25
26
# File 'lib/fin/container_list.rb', line 24

def add_record rec
  add? @item_type.from_record rec
end

#check(item) ⇒ Object



16
17
18
# File 'lib/fin/container_list.rb', line 16

def check item
  item.is_a?(@item_type) && item.index
end

#index(item) ⇒ Object



20
21
22
# File 'lib/fin/container_list.rb', line 20

def index item
  item.index if check item
end

#remove_message(msg, id) ⇒ Object



37
38
39
40
# File 'lib/fin/container_list.rb', line 37

def remove_message msg, id
  item = @item_type.from_msg msg
  remove? self[item.index]
end

#remove_record(rec, id) ⇒ Object



28
29
30
31
# File 'lib/fin/container_list.rb', line 28

def remove_record rec, id
  index = @item_type.index_for rec
  remove? self[index]
end