Class: BAWSAQ::StockCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bawsaq/stock_collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stocks) ⇒ StockCollection

Returns a new instance of StockCollection.



12
13
14
# File 'lib/bawsaq/stock_collection.rb', line 12

def initialize(stocks)
  @stocks = stocks
end

Class Method Details

.parse(json_payload) ⇒ Object



7
8
9
10
# File 'lib/bawsaq/stock_collection.rb', line 7

def self.parse(json_payload)
  dataset = MultiJson.load(json_payload)
  new(dataset['Stocks'].map(&Stock.method(:new)))
end

Instance Method Details

#[](index_or_code) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/bawsaq/stock_collection.rb', line 16

def [](index_or_code)
  case index_or_code
  when Integer
    @stocks[index_or_code]
  else
    code = index_or_code.to_s
    @stocks.find{ |s| s.company_code == code }
  end
end

#each(&block) ⇒ Object



26
27
28
# File 'lib/bawsaq/stock_collection.rb', line 26

def each(&block)
  @stocks.each(&block)
end