Class: MoneyWithDate::RatesStore::Memory

Inherits:
Money::RatesStore::Memory
  • Object
show all
Defined in:
lib/money_with_date/rates_store/memory.rb

Instance Method Summary collapse

Instance Method Details

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



6
7
8
9
10
11
12
# File 'lib/money_with_date/rates_store/memory.rb', line 6

def add_rate(currency_iso_from, currency_iso_to, rate, date)
  guard.synchronize do
    date_key = date_key_for(date)
    rates[date_key] ||= {}
    rates[date_key][rate_key_for(currency_iso_from, currency_iso_to)] = rate
  end
end

#each_rateObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/money_with_date/rates_store/memory.rb', line 20

def each_rate
  return to_enum(:each_rate) unless block_given?

  guard.synchronize do
    rates.each do |date, date_rates|
      date_rates.each do |key, rate|
        iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR)
        yield iso_from, iso_to, rate, date_for_key(date)
      end
    end
  end
end

#get_rate(currency_iso_from, currency_iso_to, date) ⇒ Object



14
15
16
17
18
# File 'lib/money_with_date/rates_store/memory.rb', line 14

def get_rate(currency_iso_from, currency_iso_to, date)
  guard.synchronize do
    rates.dig(date_key_for(date), rate_key_for(currency_iso_from, currency_iso_to))
  end
end