Class: Money::RatesStore::StoreWithDateSupport
- Inherits:
-
Memory
- Object
- Memory
- Money::RatesStore::StoreWithDateSupport
- Defined in:
- lib/money/rates_store/store_with_date_support.rb
Overview
Class for thread-safe storage of exchange rates per date.
Constant Summary collapse
- INDEX_DATE_SEPARATOR =
'_ON_'
Instance Method Summary collapse
- #add_rate(currency_iso_from, currency_iso_to, rate, date = nil) ⇒ Object
-
#each_rate {|iso_from, iso_to, rate, date| ... } ⇒ Enumerator
Iterate over exchange rate tuples.
- #get_rate(currency_iso_from, currency_iso_to, date = nil) ⇒ Object
Instance Method Details
#add_rate(currency_iso_from, currency_iso_to, rate, date = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/money/rates_store/store_with_date_support.rb', line 11 def add_rate(currency_iso_from, currency_iso_to, rate, date = nil) guard.synchronize do rates[rate_key_for(currency_iso_from, currency_iso_to, date)] = rate end end |
#each_rate {|iso_from, iso_to, rate, date| ... } ⇒ Enumerator
Iterate over exchange rate tuples
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/money/rates_store/store_with_date_support.rb', line 35 def each_rate(&_block) return to_enum(:each_rate) unless block_given? guard.synchronize do rates.each do |key, rate| iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR) iso_to, date = iso_to.split(INDEX_DATE_SEPARATOR) date = Date.parse(date) if date yield iso_from, iso_to, rate, date end end end |
#get_rate(currency_iso_from, currency_iso_to, date = nil) ⇒ Object
17 18 19 20 21 |
# File 'lib/money/rates_store/store_with_date_support.rb', line 17 def get_rate(currency_iso_from, currency_iso_to, date = nil) guard.synchronize do rates[rate_key_for(currency_iso_from, currency_iso_to, date)] end end |