abstract class Money::Currency::RateStore

Included Modules

Direct Known Subclasses

Defined in:

money/currency/rate_store.cr

Instance Method Summary

Instance Method Detail

def [](from, to) : BigDecimal #

Retrieve the rate for the given currencies.

NOTE Uses #transaction to synchronize data access.

store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 1.24515
store["USD", "CAD"]? # => 1.24515

[View source]
def []=(from, to, value : Number) : Nil #

Registers a conversion rate and returns it.

NOTE Uses #transaction to synchronize data access.

store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 1.24515
store["CAD", "USD"] = 0.803115

[View source]
def []?(from, to) : BigDecimal | Nil #

Retrieve the rate for the given currencies.

NOTE Uses #transaction to synchronize data access.

store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 1.24515
store["USD", "CAD"]? # => 1.24515

[View source]
abstract def add_rate(from : Currency, to : Currency, value : Int64) : Nil #

See #[]=.


[View source]
def clear : Nil #

Empties currency rate index.

NOTE Uses #transaction to synchronize data access.


[View source]
abstract def clear_rates : Nil #

See #clear.


[View source]
abstract def each(&block : T -> _) #

Iterates over list of Rate objects.

store.each do |rate|
  puts rate
end

[View source]
abstract def get_rate?(from : Currency, to : Currency) : Rate | Nil #

See #[]?.


[View source]
abstract def transaction(&block : -> _) #

Wraps block execution in a concurrency-safe transaction.


[View source]