Class: TickerPicker::Ticker
- Inherits:
-
Object
- Object
- TickerPicker::Ticker
- Defined in:
- lib/tickerpicker/ticker.rb
Constant Summary collapse
- @@factories =
{}
Class Method Summary collapse
-
.factories ⇒ Object
Get factories hash.
-
.get_all_stock_market_prices ⇒ Object
Get all market prices in avaliable stocks.
-
.get_all_stock_prices(stock) ⇒ Object
Get all market prices in a stock.
-
.get_prices(stock, market) ⇒ Object
Get prices for market in stock.
-
.register(stock, file_path = nil) ⇒ Object
Register a ticker factory.
-
.register_list(stocks) ⇒ Object
Register multiple ticker factories.
Class Method Details
.factories ⇒ Object
Get factories hash
Returns
-
factories- Hash
12 13 14 |
# File 'lib/tickerpicker/ticker.rb', line 12 def factories @@factories end |
.get_all_stock_market_prices ⇒ Object
Get all market prices in avaliable stocks
Parameters
-
stock- String which must be a valid stock name
Returns
-
Hash- Hash of TickerPicker::Price
89 90 91 92 93 94 95 |
# File 'lib/tickerpicker/ticker.rb', line 89 def get_all_stock_market_prices stock_market_prices = {} factories.each do |stock_key, _| stock_market_prices.merge!({ stock_key => get_all_stock_prices_without_check(stock_key) }) end stock_market_prices end |
.get_all_stock_prices(stock) ⇒ Object
Get all market prices in a stock
Parameters
-
stock- String which must be a valid stock name
Returns
-
Hash- Hash of TickerPicker::Price
74 75 76 77 |
# File 'lib/tickerpicker/ticker.rb', line 74 def get_all_stock_prices(stock) return stock_does_not_exists unless factories.has_key?(stock) get_all_stock_prices_without_check(stock) end |
.get_prices(stock, market) ⇒ Object
Get prices for market in stock
Parameters
-
stock- String which must be a valid stock name -
market- String which should include valid market name
Returns
-
TickerPicker::Price- Extended version of TickerPicker::Price with factory key
59 60 61 62 |
# File 'lib/tickerpicker/ticker.rb', line 59 def get_prices(stock, market) return stock_market_does_not_exists unless (factories[stock] || {}).has_key?(market) get_price_without_check(stock, market) end |
.register(stock, file_path = nil) ⇒ Object
Register a ticker factory
Parameters
-
stock- Factory object name -
file_path- Optional load path for stock handler factory for new dev purposes
Returns
-
true- Boolean
27 28 29 30 31 |
# File 'lib/tickerpicker/ticker.rb', line 27 def register(stock, file_path = nil) require (file_path || "#{File.dirname(__FILE__)}/factory/#{stock}") factories[stock] = eval("TickerPicker::Factory::#{stock.capitalize}.markets") true end |
.register_list(stocks) ⇒ Object
Register multiple ticker factories
Parameters
-
stocks- Factory object name list
Returns
-
true- Boolean
43 44 45 46 |
# File 'lib/tickerpicker/ticker.rb', line 43 def register_list(stocks) stocks.each { |stock| register(stock) } true end |