class CoinMarket::Ticker

Attributes

attributes[R]

Public Class Methods

all() click to toggle source
# File lib/coin_market/ticker.rb, line 10
def all
  get(nil)
end
get(id) click to toggle source
# 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
new(obj) click to toggle source
# File lib/coin_market/ticker.rb, line 17
def initialize(obj)
  @attributes = obj
end

Public Instance Methods

available_supply() click to toggle source
# File lib/coin_market/ticker.rb, line 25
def available_supply; attributes['available_supply'].to_f; end
id() click to toggle source
# File lib/coin_market/ticker.rb, line 21
def id; attributes['id']; end
last_updated() click to toggle source
# File lib/coin_market/ticker.rb, line 57
def last_updated
  Time.at(attributes['last_updated'].to_f)
end
market_cap(options={}) click to toggle source
# File lib/coin_market/ticker.rb, line 43
def market_cap(options={})
  currency = options[:currency] || 'usd'
  key = "market_cap_#{currency}"

  attributes.has_key?(key) ? attributes[key].to_f : nil
end
name() click to toggle source
# File lib/coin_market/ticker.rb, line 22
def name; attributes['name']; end
percent_change(options={}) click to toggle source
# File lib/coin_market/ticker.rb, line 50
def percent_change(options={})
  period = options[:period] || '24h'
  key = "percent_change_#{period}"

  attributes.has_key?(key) ? attributes[key].to_f : nil
end
price(options={}) click to toggle source
# File lib/coin_market/ticker.rb, line 28
def price(options={})
  currency = options[:currency] || 'usd'
  key = "price_#{currency}"

  attributes.has_key?(key) ? attributes[key].to_f : nil
end
rank() click to toggle source
# File lib/coin_market/ticker.rb, line 24
def rank; attributes['rank'].to_f; end
symbol() click to toggle source
# File lib/coin_market/ticker.rb, line 23
def symbol; attributes['symbol']; end
total_supply() click to toggle source
# File lib/coin_market/ticker.rb, line 26
def total_supply; attributes['total_supply'].to_f; end
volume(options={}) click to toggle source
# File lib/coin_market/ticker.rb, line 35
def volume(options={})
  period = options[:period] || '24h'
  currency = options[:currency] || 'usd'
  key = "#{period}_volume_#{currency}"

  attributes.has_key?(key) ? attributes[key].to_f : nil
end