Class: CoinTools::CoinMarketCap::CoinData
- Defined in:
- lib/cointools/coinmarketcap.rb
Instance Attribute Summary collapse
-
#btc_price ⇒ Object
readonly
Returns the value of attribute btc_price.
-
#converted_price ⇒ Object
readonly
Returns the value of attribute converted_price.
-
#last_updated ⇒ Object
readonly
Returns the value of attribute last_updated.
-
#market_cap ⇒ Object
readonly
Returns the value of attribute market_cap.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#usd_price ⇒ Object
readonly
Returns the value of attribute usd_price.
Attributes inherited from Listing
#name, #numeric_id, #symbol, #text_id
Instance Method Summary collapse
-
#initialize(json, convert_to = nil) ⇒ CoinData
constructor
A new instance of CoinData.
Constructor Details
#initialize(json, convert_to = nil) ⇒ CoinData
Returns a new instance of CoinData.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cointools/coinmarketcap.rb', line 38 def initialize(json, convert_to = nil) super(json) raise ArgumentError.new('Missing rank field') unless json['rank'] raise ArgumentError.new('Invalid rank field') unless json['rank'].is_a?(Integer) && json['rank'] > 0 @rank = json['rank'] quotes = json['quotes'] raise ArgumentError.new('Missing quotes field') unless quotes raise ArgumentError.new('Invalid quotes field') unless quotes.is_a?(Hash) usd_quote = quotes['USD'] raise ArgumentError.new('Missing USD quote info') unless usd_quote raise ArgumentError.new('Invalid USD quote info') unless usd_quote.is_a?(Hash) @usd_price = usd_quote['price']&.to_f @market_cap = usd_quote['market_cap']&.to_f if convert_to converted_quote = quotes[convert_to.upcase] if converted_quote raise ArgumentError.new("Invalid #{convert_to.upcase} quote info") unless converted_quote.is_a?(Hash) @converted_price = converted_quote['price']&.to_f end else btc_quote = quotes['BTC'] if btc_quote raise ArgumentError.new("Invalid BTC quote info") unless btc_quote.is_a?(Hash) @btc_price = btc_quote['price']&.to_f end end = json['last_updated'] @last_updated = Time.at() if end |
Instance Attribute Details
#btc_price ⇒ Object (readonly)
Returns the value of attribute btc_price.
36 37 38 |
# File 'lib/cointools/coinmarketcap.rb', line 36 def btc_price @btc_price end |
#converted_price ⇒ Object (readonly)
Returns the value of attribute converted_price.
36 37 38 |
# File 'lib/cointools/coinmarketcap.rb', line 36 def converted_price @converted_price end |
#last_updated ⇒ Object (readonly)
Returns the value of attribute last_updated.
36 37 38 |
# File 'lib/cointools/coinmarketcap.rb', line 36 def last_updated @last_updated end |
#market_cap ⇒ Object (readonly)
Returns the value of attribute market_cap.
36 37 38 |
# File 'lib/cointools/coinmarketcap.rb', line 36 def market_cap @market_cap end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
36 37 38 |
# File 'lib/cointools/coinmarketcap.rb', line 36 def rank @rank end |
#usd_price ⇒ Object (readonly)
Returns the value of attribute usd_price.
36 37 38 |
# File 'lib/cointools/coinmarketcap.rb', line 36 def usd_price @usd_price end |