class Money
Attributes
amount[R]
currency[R]
Public Class Methods
conversion_rates(*args)
click to toggle source
# File lib/currency_work/money.rb, line 8 def self.conversion_rates(*args) base = args[0] values = { base => 1.0 }.merge(args[1]) Rate.instance.define_attrs(base, values) end
new(*args)
click to toggle source
# File lib/currency_work/money.rb, line 14 def initialize(*args) @amount, @currency = args end
Public Instance Methods
*(other)
click to toggle source
# File lib/currency_work/money.rb, line 56 def *(other) Money.new(amount * other, currency) end
+(other)
click to toggle source
# File lib/currency_work/money.rb, line 32 def +(other) value = Rate.instance.convert_to( amount: other.amount, origin_currency: other.currency, new_currency: currency ) Money.new(value + amount, currency) end
-(other)
click to toggle source
# File lib/currency_work/money.rb, line 42 def -(other) value = Rate.instance.convert_to( amount: other.amount, origin_currency: other.currency, new_currency: currency ) Money.new(amount - value, currency) end
/(other)
click to toggle source
# File lib/currency_work/money.rb, line 52 def /(other) Money.new(amount / other, currency) end
<(other)
click to toggle source
# File lib/currency_work/money.rb, line 68 def <(other) amount.round(2) < other.convert_to(currency).amount.round(2) end
==(other)
click to toggle source
# File lib/currency_work/money.rb, line 60 def ==(other) other.convert_to(currency).amount.round(2) == amount.round(2) end
>(other)
click to toggle source
# File lib/currency_work/money.rb, line 64 def >(other) amount.round(2) > other.convert_to(currency).amount.round(2) end
convert_to(new_currency)
click to toggle source
# File lib/currency_work/money.rb, line 22 def convert_to(new_currency) value = Rate.instance.convert_to( amount: amount, origin_currency: currency, new_currency: new_currency ) Money.new(value, new_currency) end
inspect()
click to toggle source
# File lib/currency_work/money.rb, line 18 def inspect "#{format('%.2f', amount)} #{currency}" end