Class: TickerPicker::Price
- Inherits:
-
Object
- Object
- TickerPicker::Price
- Includes:
- Hashable
- Defined in:
- lib/tickerpicker/price.rb
Direct Known Subclasses
Factory::Bitstamp, Factory::Btce, Factory::Btcturk, Factory::Mtgox
Instance Attribute Summary collapse
-
#ask ⇒ Object
Returns the value of attribute ask.
-
#bid ⇒ Object
Returns the value of attribute bid.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#last ⇒ Object
Returns the value of attribute last.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.gather_info(url) ⇒ Object
Get information from stock-market uri and convert it into Hash.
-
.get_prices(market) ⇒ Object
Get prices for the market.
-
.instance_mapping ⇒ Object
Abstact method for mapping foreign data with local instance.
-
.markets ⇒ Object
Abstact method for list of markets in the stock.
-
.user_agent ⇒ Object
nodoc.
Instance Method Summary collapse
-
#initialize(price_hash = {}) ⇒ Price
constructor
A new instance of Price.
Constructor Details
#initialize(price_hash = {}) ⇒ Price
Returns a new instance of Price.
11 12 13 14 15 16 17 |
# File 'lib/tickerpicker/price.rb', line 11 def initialize(price_hash = {}) @ask = price_hash[:ask] || 0.0 @bid = price_hash[:bid] || 0.0 @currency = price_hash[:currency] || '' @last = price_hash[:last] || 0.0 @timestamp = price_hash[:timestamp].to_f || Time.now.to_f end |
Instance Attribute Details
#ask ⇒ Object
Returns the value of attribute ask.
5 6 7 |
# File 'lib/tickerpicker/price.rb', line 5 def ask @ask end |
#bid ⇒ Object
Returns the value of attribute bid.
6 7 8 |
# File 'lib/tickerpicker/price.rb', line 6 def bid @bid end |
#currency ⇒ Object
Returns the value of attribute currency.
7 8 9 |
# File 'lib/tickerpicker/price.rb', line 7 def currency @currency end |
#last ⇒ Object
Returns the value of attribute last.
8 9 10 |
# File 'lib/tickerpicker/price.rb', line 8 def last @last end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
9 10 11 |
# File 'lib/tickerpicker/price.rb', line 9 def @timestamp end |
Class Method Details
.gather_info(url) ⇒ Object
Get information from stock-market uri and convert it into Hash
Parameters
-
url- Stock market URI
Returns
-
Hash- Hash of information for given stock-market uri
56 57 58 59 |
# File 'lib/tickerpicker/price.rb', line 56 def gather_info(url) response = url =~ URI::regexp ? open(url, 'User-Agent' => user_agent, read_timeout: 2).read : open(url).read JSON.parse(response) end |
.get_prices(market) ⇒ Object
Get prices for the market
Parameters
-
market- string
Returns
-
TickerPicker::Price- TickerPicker::Price instance object
30 31 32 |
# File 'lib/tickerpicker/price.rb', line 30 def get_prices(market) instance_mapping gather_info(markets[market]['url']), markets[market]['currency'] end |
.instance_mapping ⇒ Object
Abstact method for mapping foreign data with local instance
42 43 44 |
# File 'lib/tickerpicker/price.rb', line 42 def instance_mapping raise NotImplementedError.new("#{self.class.name}##{__callee__} method is not implemented!") end |
.markets ⇒ Object
Abstact method for list of markets in the stock
36 37 38 |
# File 'lib/tickerpicker/price.rb', line 36 def markets raise NotImplementedError.new("#{self.class.name}##{__callee__} method is not implemented!") end |
.user_agent ⇒ Object
nodoc
62 63 64 |
# File 'lib/tickerpicker/price.rb', line 62 def user_agent "TickerPicker Bot v#{TickerPicker::VERSION}" end |