class Money::RatesStore::StoreWithHistoricalDataSupport
Constants
- INDEX_DATE_SEPARATOR
Public Instance Methods
add_rate(currency_iso_from, currency_iso_to, rate, date = nil)
click to toggle source
# File lib/money/rates_store/store_with_historical_data_support.rb, line 5 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_rate(&block)
click to toggle source
Iterate over rate tuples (iso_from, iso_to, rate)
@yieldparam iso_from [String] Currency ISO string. @yieldparam iso_to [String] Currency ISO string. @yieldparam rate [Numeric] Exchange rate. @yieldparam date [Date] Historical date for the exchange rate. Nil if the rate is not historical rate.
@return [Enumerator]
@example
store.each_rate do |iso_from, iso_to, rate, date| puts [iso_from, iso_to, rate, date].join end
# File lib/money/rates_store/store_with_historical_data_support.rb, line 31 def each_rate(&block) 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(&block) : enum end
get_rate(currency_iso_from, currency_iso_to, date = nil)
click to toggle source
# File lib/money/rates_store/store_with_historical_data_support.rb, line 9 def get_rate(currency_iso_from, currency_iso_to, date = nil) transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] } end
transaction(_force_sync = false, &block)
click to toggle source
Wraps block execution in a thread-safe transaction
Calls superclass method
# File lib/money/rates_store/store_with_historical_data_support.rb, line 14 def transaction(_force_sync = false, &block) super(&block) end
Private Instance Methods
rate_key_for(currency_iso_from, currency_iso_to, date = nil)
click to toggle source
# File lib/money/rates_store/store_with_historical_data_support.rb, line 46 def rate_key_for(currency_iso_from, currency_iso_to, date = nil) key = [currency_iso_from, currency_iso_to].join(Memory::INDEX_KEY_SEPARATOR) key = [key, date.to_s].join(INDEX_DATE_SEPARATOR) if date key.upcase end