class CoinMarketCap::Coin

Coin class

Attributes

coin[RW]

Public Class Methods

new(coin) click to toggle source
# File lib/coin_market_cap/coin.rb, line 9
def initialize(coin)
  @coin = coin.downcase
  @currencies = fetch_coin_prices
end

Public Instance Methods

price() click to toggle source
# File lib/coin_market_cap/coin.rb, line 14
def price
        @currencies[@coin]
end

Private Instance Methods

fetch_coin_prices() click to toggle source
# File lib/coin_market_cap/coin.rb, line 20
        def fetch_coin_prices
                doc = Nokogiri::HTML(open(COIN_MARKET_CAP_URL))
                currencies = {}

                doc.css("#currencies tbody tr").each do |coin|
currency = coin.css("td a.currency-name-container").text.downcase.gsub(" ", "_")
price = coin.css("td .price").attribute('data-usd').value.to_f
                        currencies[currency] = price
                end
                currencies
        end