class Money::Currency::Exchange::SingleCurrency

Overview

Class to ensure client code is operating in a single currency by raising if an exchange attempts to happen.

This is useful when an application uses multiple currencies but it usually deals with only one currency at a time so any arithmetic where exchanges happen are erroneous. Using this as the default exchange means that that these mistakes don't silently do the wrong thing.

Defined in:

money/currency/exchange/single_currency.cr

Instance Method Summary

Instance methods inherited from class Money::Currency::Exchange

base_currencies : Array(Currency) base_currencies, exchange(from : Money, to : Currency) : Money exchange, exchange_rate(base : Currency, target : Currency) : BigDecimal exchange_rate, exchange_rate?(base : Currency, target : Currency) : BigDecimal | Nil exchange_rate?, rate_provider : RateProvider rate_provider, rate_provider=(rate_provider : RateProvider | Nil) rate_provider=, rate_store : RateStore rate_store, rate_store=(rate_store : RateStore | Nil) rate_store=, target_currencies : Array(Currency) target_currencies

Constructor methods inherited from class Money::Currency::Exchange

new(rate_store : Money::Currency::RateStore | Nil = nil, rate_provider : Money::Currency::RateProvider | Nil = nil) new

Instance Method Detail

def exchange(from : Money, to : Currency) : Money #

Raises a DifferentCurrencyError to remove possibility of accidentally exchanging currencies.


[View source]