Class: CoinMarket::Ticker
- Inherits:
-
Object
- Object
- CoinMarket::Ticker
- Defined in:
- lib/coin_market/ticker.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #available_supply ⇒ Object
- #id ⇒ Object
-
#initialize(obj) ⇒ Ticker
constructor
A new instance of Ticker.
- #last_updated ⇒ Object
- #market_cap(options = {}) ⇒ Object
- #name ⇒ Object
- #percent_change(options = {}) ⇒ Object
- #price(options = {}) ⇒ Object
- #rank ⇒ Object
- #symbol ⇒ Object
- #total_supply ⇒ Object
- #volume(options = {}) ⇒ Object
Constructor Details
#initialize(obj) ⇒ Ticker
Returns a new instance of Ticker.
17 18 19 |
# File 'lib/coin_market/ticker.rb', line 17 def initialize(obj) @attributes = obj end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
15 16 17 |
# File 'lib/coin_market/ticker.rb', line 15 def attributes @attributes end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/coin_market/ticker.rb', line 10 def all get(nil) end |
.get(id) ⇒ Object
4 5 6 7 8 |
# File 'lib/coin_market/ticker.rb', line 4 def get(id) response = CoinMarket::Client.new.request('ticker', id) tickers = response.map { |obj| CoinMarket::Ticker.new(obj) } tickers.length > 1 ? tickers : tickers[0] end |
Instance Method Details
#available_supply ⇒ Object
25 |
# File 'lib/coin_market/ticker.rb', line 25 def available_supply; attributes['available_supply'].to_f; end |
#id ⇒ Object
21 |
# File 'lib/coin_market/ticker.rb', line 21 def id; attributes['id']; end |
#last_updated ⇒ Object
57 58 59 |
# File 'lib/coin_market/ticker.rb', line 57 def last_updated Time.at(attributes['last_updated'].to_f) end |
#market_cap(options = {}) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/coin_market/ticker.rb', line 43 def market_cap(={}) currency = [:currency] || 'usd' key = "market_cap_#{currency}" attributes.has_key?(key) ? attributes[key].to_f : nil end |
#name ⇒ Object
22 |
# File 'lib/coin_market/ticker.rb', line 22 def name; attributes['name']; end |
#percent_change(options = {}) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/coin_market/ticker.rb', line 50 def percent_change(={}) period = [:period] || '24h' key = "percent_change_#{period}" attributes.has_key?(key) ? attributes[key].to_f : nil end |
#price(options = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/coin_market/ticker.rb', line 28 def price(={}) currency = [:currency] || 'usd' key = "price_#{currency}" attributes.has_key?(key) ? attributes[key].to_f : nil end |
#rank ⇒ Object
24 |
# File 'lib/coin_market/ticker.rb', line 24 def rank; attributes['rank'].to_f; end |
#symbol ⇒ Object
23 |
# File 'lib/coin_market/ticker.rb', line 23 def symbol; attributes['symbol']; end |
#total_supply ⇒ Object
26 |
# File 'lib/coin_market/ticker.rb', line 26 def total_supply; attributes['total_supply'].to_f; end |
#volume(options = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/coin_market/ticker.rb', line 35 def volume(={}) period = [:period] || '24h' currency = [:currency] || 'usd' key = "#{period}_volume_#{currency}" attributes.has_key?(key) ? attributes[key].to_f : nil end |