abstract class
Money::Currency::RateStore
- Money::Currency::RateStore
- Reference
- Object
Included Modules
- Enumerable(Money::Currency::Rate)
Direct Known Subclasses
Defined in:
money/currency/rate_store.crConstructors
Instance Method Summary
-
#<<(rate : Rate) : self
Registers a conversion rate.
-
#<<(rates : Enumerable(Rate)) : self
Registers multiple conversion rates.
-
#[](from : String | Symbol | Currency, to : String | Symbol | Currency) : BigDecimal
Retrieves the rate for the given currency pair or raises
UnknownRateError
if not found. -
#[]=(from : String | Symbol | Currency, to : String | Symbol | Currency, value : Number) : Nil
Registers a conversion rate.
-
#[]?(from : String | Symbol | Currency, to : String | Symbol | Currency) : BigDecimal | Nil
Retrieves the rate for the given currency pair or
nil
if not found. -
#clear(base_currency : String | Symbol | Currency) : Nil
Removes rates for the given base currency.
-
#clear : Nil
Empties currency rate index.
-
#each(& : Rate -> _) : Nil
Iterates over list of
Rate
objects. -
#rates : Array(Rate)
Alias of
#to_a
. -
#transaction(*, mutable : Bool = false, & : -> _)
Wraps block execution in a concurrency-safe transaction.
Constructor Detail
Instance Method Detail
Registers a conversion rate.
store = Money::Currency::RateStore::Memory.new
store << Rate.new(
Money::Currency.find("USD"),
Money::Currency.find("CAD"),
1.24515.to_big_d
)
store << Rate.new(
Money::Currency.find("CAD"),
Money::Currency.find("USD"),
0.803115.to_big_d
)
Registers multiple conversion rates.
store = Money::Currency::RateStore::Memory.new
store << [
Rate.new(
Money::Currency.find("USD"),
Money::Currency.find("CAD"),
1.24515.to_big_d
),
Rate.new(
Money::Currency.find("CAD"),
Money::Currency.find("USD"),
0.803115.to_big_d
),
]
Retrieves the rate for the given currency pair or raises
UnknownRateError
if not found.
store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 1.24515
store["USD", "CAD"] # => 1.24515
store["CAD", "USD"] # raises UnknownRateError
Registers a conversion rate.
store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 1.24515
store["CAD", "USD"] = 0.803115
Retrieves the rate for the given currency pair or nil
if not found.
store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 1.24515
store["USD", "CAD"]? # => 1.24515
store["CAD", "USD"]? # => nil
Removes rates for the given base currency.
Iterates over list of Rate
objects.
store.each do |rate|
puts rate
end
Wraps block execution in a concurrency-safe transaction.