Class: ExchangerateApi::Result
- Inherits:
-
Object
- Object
- ExchangerateApi::Result
- Extended by:
- Forwardable
- Defined in:
- lib/exchangerate_api/result.rb
Overview
# Result
Exchange rate response data wrapper.
Instance Attribute Summary collapse
-
#currency_code ⇒ String
readonly
ISO format currency code.
-
#date ⇒ Time
readonly
Exchange rate updated date.
-
#rates ⇒ Hash<String,Float>
readonly
Exchange rate data by currency.
-
#updated_at ⇒ Time
readonly
Exchange rate updated timestamp.
Instance Method Summary collapse
-
#[](currency_code) ⇒ Float?
Get exchage rate by currency code.
-
#currency_codes ⇒ Array<String>
List of currency codes.
-
#initialize(data) ⇒ Result
constructor
A new instance of Result.
Constructor Details
#initialize(data) ⇒ Result
Returns a new instance of Result.
28 29 30 31 32 33 |
# File 'lib/exchangerate_api/result.rb', line 28 def initialize(data) @currency_code = data['base'] @date = Time.new(data['date']).utc @updated_at = Time.at(data['time_last_updated']).utc @rates = data['rates'] end |
Instance Attribute Details
#currency_code ⇒ String (readonly)
Returns ISO format currency code.
16 17 18 |
# File 'lib/exchangerate_api/result.rb', line 16 def currency_code @currency_code end |
#date ⇒ Time (readonly)
Returns Exchange rate updated date.
19 20 21 |
# File 'lib/exchangerate_api/result.rb', line 19 def date @date end |
#rates ⇒ Hash<String,Float> (readonly)
Returns Exchange rate data by currency.
25 26 27 |
# File 'lib/exchangerate_api/result.rb', line 25 def rates @rates end |
#updated_at ⇒ Time (readonly)
Returns Exchange rate updated timestamp.
22 23 24 |
# File 'lib/exchangerate_api/result.rb', line 22 def updated_at @updated_at end |
Instance Method Details
#[](currency_code) ⇒ Float?
Get exchage rate by currency code.
38 39 40 |
# File 'lib/exchangerate_api/result.rb', line 38 def [](currency_code) @rates[currency_code] end |
#currency_codes ⇒ Array<String>
List of currency codes
45 46 47 |
# File 'lib/exchangerate_api/result.rb', line 45 def currency_codes @rates.keys end |