Class: Money::RatesStore::NbrbHistoricalStore

Inherits:
Memory
  • Object
show all
Defined in:
lib/money/rates_store/nbrb_historical_store.rb

Constant Summary collapse

INDEX_DATE_SEPARATOR =
'_AT_'

Instance Method Summary collapse

Instance Method Details

#add_rate(currency_iso_from, currency_iso_to, rate, date = nil) ⇒ Object



8
9
10
# File 'lib/money/rates_store/nbrb_historical_store.rb', line 8

def add_rate(currency_iso_from, currency_iso_to, rate, date = nil)
  transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] = rate }
end

#each_rateObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/money/rates_store/nbrb_historical_store.rb', line 16

def each_rate(&)
  enum = Enumerator.new do |yielder|
    rates.each do |key, rate|
      iso_from, iso_to = key.split(Memory::INDEX_KEY_SEPARATOR)
      iso_to, date = iso_to.split(INDEX_DATE_SEPARATOR)
      date = Date.parse(date) if date
      yielder.yield iso_from, iso_to, rate, date
    end
  end

  block_given? ? enum.each(&) : enum
end

#get_rate(currency_iso_from, currency_iso_to, date = nil) ⇒ Object



12
13
14
# File 'lib/money/rates_store/nbrb_historical_store.rb', line 12

def get_rate(currency_iso_from, currency_iso_to, date = nil)
  transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] }
end