class Money::Test::Money
Attributes
amount[R]
currency[R]
Public Class Methods
new(amount, currency)
click to toggle source
# File lib/money/test/money.rb, line 6 def initialize(amount, currency) @amount = amount @currency = currency end
Public Instance Methods
*(multiply)
click to toggle source
# File lib/money/test/money.rb, line 27 def *(multiply) Money.new amount * multiply, currency end
+(other)
click to toggle source
# File lib/money/test/money.rb, line 19 def +(other) Money.new amount + other.exchange_amount(currency), currency end
-(other)
click to toggle source
# File lib/money/test/money.rb, line 23 def -(other) Money.new amount - other.exchange_amount(currency), currency end
/(divide)
click to toggle source
# File lib/money/test/money.rb, line 31 def /(divide) Money.new amount / divide, currency end
<(other)
click to toggle source
# File lib/money/test/money.rb, line 43 def <(other) compare with: other, operator: :< end
==(other)
click to toggle source
# File lib/money/test/money.rb, line 35 def ==(other) compare with: other, operator: :== end
>(other)
click to toggle source
# File lib/money/test/money.rb, line 39 def >(other) compare with: other, operator: :> end
convert_to(new_currency)
click to toggle source
# File lib/money/test/money.rb, line 15 def convert_to(new_currency) Money.new exchange_amount(new_currency), new_currency end
exchange_amount(new_currency)
click to toggle source
# File lib/money/test/money.rb, line 47 def exchange_amount(new_currency) @amount * exchange_rate(new_currency) end
inspect()
click to toggle source
# File lib/money/test/money.rb, line 11 def inspect sprintf '%.2f %s', @amount, @currency end
Private Instance Methods
compare(operator:, with:)
click to toggle source
# File lib/money/test/money.rb, line 57 def compare(operator:, with:) amount.send(operator, with.exchange_amount(currency)) end
exchange_rate(new_currency)
click to toggle source
# File lib/money/test/money.rb, line 53 def exchange_rate(new_currency) Rate.exchange_rate(from_currency: @currency, to_currency: new_currency) end