Class: ExchangerateApi::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/exchangerate_api/result.rb

Overview

# Result

Exchange rate response data wrapper.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_codeString (readonly)

Returns ISO format currency code.

Returns:

  • (String)

    ISO format currency code.



16
17
18
# File 'lib/exchangerate_api/result.rb', line 16

def currency_code
  @currency_code
end

#dateTime (readonly)

Returns Exchange rate updated date.

Returns:

  • (Time)

    Exchange rate updated date.



19
20
21
# File 'lib/exchangerate_api/result.rb', line 19

def date
  @date
end

#ratesHash<String,Float> (readonly)

Returns Exchange rate data by currency.

Returns:

  • (Hash<String,Float>)

    Exchange rate data by currency.



25
26
27
# File 'lib/exchangerate_api/result.rb', line 25

def rates
  @rates
end

#updated_atTime (readonly)

Returns Exchange rate updated timestamp.

Returns:

  • (Time)

    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.

Returns:

  • (Float, nil)

    Exchange value



38
39
40
# File 'lib/exchangerate_api/result.rb', line 38

def [](currency_code)
  @rates[currency_code]
end

#currency_codesArray<String>

List of currency codes

Returns:

  • (Array<String>)


45
46
47
# File 'lib/exchangerate_api/result.rb', line 45

def currency_codes
  @rates.keys
end