class ExchangerateApi::Result

# Result

Exchange rate response data wrapper.

Attributes

currency_code[R]

@return [String] ISO format currency code.

date[R]

@return [Time] Exchange rate updated date.

rates[R]

@return [Hash<String,Float>] Exchange rate data by currency.

updated_at[R]

@return [Time] Exchange rate updated timestamp.

Public Class Methods

new(data) click to toggle source

@private

# 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

Public Instance Methods

[](currency_code) click to toggle source

Get exchage rate by currency code.

@return [Float,nil] Exchange value

# File lib/exchangerate_api/result.rb, line 38
def [](currency_code)
  @rates[currency_code]
end
currency_codes() click to toggle source

List of currency codes

@return [Array<String>]

# File lib/exchangerate_api/result.rb, line 45
def currency_codes
  @rates.keys
end