class Money::Test::Rate
Constants
- NUMBER_OF_DIGITS
Public Class Methods
exchange_rate(from_currency:, to_currency:)
click to toggle source
# File lib/money/test/rate.rb, line 18 def exchange_rate(from_currency:, to_currency:) if from_currency == to_currency 1 elsif base? from_currency from_base to: to_currency elsif base? to_currency to_base from: from_currency else convert from: from_currency, to: to_currency end end
load_conversions(base_currency:, rates:)
click to toggle source
# File lib/money/test/rate.rb, line 9 def load_conversions(base_currency:, rates:) @@base_currency = base_currency @@rates = rates end
update(rates:)
click to toggle source
# File lib/money/test/rate.rb, line 14 def update(rates:) @@rates = rates end
Private Class Methods
base?(currency)
click to toggle source
# File lib/money/test/rate.rb, line 32 def base?(currency) currency == base_currency end
base_currency()
click to toggle source
# File lib/money/test/rate.rb, line 52 def base_currency @@base_currency end
convert(from:, to:)
click to toggle source
# File lib/money/test/rate.rb, line 36 def convert(from:, to:) round(to_base(from: from) * from_base(to: to)) end
from_base(to:)
click to toggle source
# File lib/money/test/rate.rb, line 40 def from_base(to:) rates[to] end
rates()
click to toggle source
# File lib/money/test/rate.rb, line 56 def rates @@rates end
round(value)
click to toggle source
# File lib/money/test/rate.rb, line 48 def round(value) value.round NUMBER_OF_DIGITS end
to_base(from:)
click to toggle source
# File lib/money/test/rate.rb, line 44 def to_base(from:) round(1 / rates[from]) end