Class: Nordea::ExchangeRates
- Inherits:
-
Object
- Object
- Nordea::ExchangeRates
- Defined in:
- lib/nordea/exchange_rates.rb
Overview
Fetch and update Excahnge rates from Nordea Bank.
Parses the custom dataformat used by Nordea into more useful Ruby types and objects.
Constant Summary collapse
- DATA_URI =
URI to the machine readable data file.
URI::HTTP.build({ :host => "openpages.nordea.com", :path => "/fi/lists/currency/elelctronicExchangeFI.dat" })
- FLOAT_KEYS =
Hash keys for key-value pairs that should be converted into floats.
[ :middle_rate_for_commercial_transactions, :buying_rate_for_commercial_transactions, :selling_rate_for_commercial_transactions, :buying_rate_for_cash, :selling_rate_for_cash ]
Instance Method Summary collapse
-
#currencies(force = false) ⇒ Hash
List all currencies as a hash.
-
#headers(force = false) ⇒ Hash
The batch headers.
-
#initialize ⇒ ExchangeRates
constructor
Initialize a new Nordea::ExchangeRates object.
Constructor Details
#initialize ⇒ ExchangeRates
Initialize a new Nordea::ExchangeRates object.
29 30 |
# File 'lib/nordea/exchange_rates.rb', line 29 def initialize end |
Instance Method Details
#currencies(force = false) ⇒ Hash
List all currencies as a hash. Uses the currencies’ ISO codes as keys.
85 86 87 88 89 90 91 92 93 |
# File 'lib/nordea/exchange_rates.rb', line 85 def currencies(force = false) hash = {} records_array(force).each do |record| hash[record[:currency_iso_code]] = record end hash end |
#headers(force = false) ⇒ Hash
The batch headers
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/nordea/exchange_rates.rb', line 36 def headers(force = false) header_line = lines(force).first unpacked = header_line.unpack("A4A3A14A120A9") headers = { :file_id => unpacked[0], # File ID = VK01 :record_id => unpacked[1], # Record ID = 000 :change_time => unpacked[2], # Exchange rate change time :notifications => unpacked[3], # Notifications :reserved => unpacked[4] # Reserved } headers.each do |key, value| headers[key] = value.force_encoding("ascii") if value.respond_to?(:force_encoding) end headers[:change_time] = Nordea.parse_time(headers[:change_time]) headers[:notifications].strip! if headers[:notifications].respond_to? :strip! headers[:reserved].strip! if headers[:reserved].respond_to? :strip! headers end |