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 => "service.nordea.com", :path => "/nordea-openpages/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.
79 80 81 82 83 84 85 86 87 |
# File 'lib/nordea/exchange_rates.rb', line 79 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 |
# File 'lib/nordea/exchange_rates.rb', line 36 def headers(force = false) header_line = lines(force).first headers = { :file_id => header_line[0..3], # File ID = VK01 :record_id => header_line[4..6], # Record ID = 000 :change_time => header_line[7..20], # Exchange rate change time :notifications => header_line[21..140], # Notifications :reserved => header_line[141..149] # Reserved } 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 |