Class: Nomics::Currency
- Inherits:
-
Object
- Object
- Nomics::Currency
- Defined in:
- lib/nomics/currency.rb
Constant Summary collapse
- ATTTRIBUTES_WITH_TYPES =
{ 'id' => :string, 'currency' => :string, 'symbol' => :symbol, 'name' => :string, 'logo_url' => :string, 'status' => :string, 'price' => :number, 'price_date' => :timestamp, 'price_timestamp' => :timestamp, 'circulating_supply' => :number, 'max_supply' => :number, 'market_cap' => :number, 'market_cap_dominance' => :number, 'num_exchanges' => :number, 'num_pairs' => :number, 'num_pairs_unmapped' => :number, 'first_candle' => :timestamp, 'first_trade' => :timestamp, 'first_order_book' => :timestamp, 'rank' => :number, 'rank_delta' => :number, 'high' => :number, 'high_timestamp' => :timestamp }.freeze
Instance Attribute Summary collapse
-
#quote_currency ⇒ Object
readonly
Returns the value of attribute quote_currency.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #<=>(other_currency) ⇒ Object
- #attributes(reload: false) ⇒ Object
-
#initialize(symbol, convert: :USD) ⇒ Currency
constructor
A new instance of Currency.
- #reload ⇒ Object
Constructor Details
#initialize(symbol, convert: :USD) ⇒ Currency
Returns a new instance of Currency.
34 35 36 37 38 39 40 41 |
# File 'lib/nomics/currency.rb', line 34 def initialize(symbol, convert: :USD) @symbol = symbol.to_s.upcase.to_sym @quote_currency = convert.to_s.upcase.to_sym ATTTRIBUTES_WITH_TYPES.except('symbol').keys.each do |attribute_name| instance_variable_set("@#{attribute_name}", nil) end end |
Instance Attribute Details
#quote_currency ⇒ Object (readonly)
Returns the value of attribute quote_currency.
32 33 34 |
# File 'lib/nomics/currency.rb', line 32 def quote_currency @quote_currency end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
32 33 34 |
# File 'lib/nomics/currency.rb', line 32 def symbol @symbol end |
Instance Method Details
#<=>(other_currency) ⇒ Object
43 44 45 |
# File 'lib/nomics/currency.rb', line 43 def <=>(other_currency) name <=> other_currency.name end |
#attributes(reload: false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nomics/currency.rb', line 53 def attributes(reload: false) if reload @attributes = attributes_with_types data.slice(*ATTTRIBUTES_WITH_TYPES.keys) else @attributes ||= attributes_with_types data.slice(*ATTTRIBUTES_WITH_TYPES.keys) end @attributes.each do |(attribute_name, attribute_value)| instance_variable_set("@#{attribute_name}", attribute_value) end end |
#reload ⇒ Object
65 66 67 68 |
# File 'lib/nomics/currency.rb', line 65 def reload attributes reload: true self end |