module Money_DaWanda::Arithmetics

Public Instance Methods

*(number) click to toggle source
# File lib/Money_DaWanda/arithmetics.rb, line 20
def *(number)
  raise ArgumentError, 'Number should be a non nil numeric'  unless number.is_a?(Numeric) and number != 0
    return Money.new((@amount * number).round(2), @currency)
end
+(money) click to toggle source
# File lib/Money_DaWanda/arithmetics.rb, line 4
def +(money)
  if money.currency != @currency && money.amount != 0
    return Money.new(@amount + (money.convert_to(@currency)).amount, @currency)
  elsif money.amount != 0  #if money.amount == 0 we don't even bother creating a new Money instance
    return Money.new(@amount + money.amount, @currency)
  end
end
-(money) click to toggle source
# File lib/Money_DaWanda/arithmetics.rb, line 12
def -(money)
  if money.currency != @currency && money.amount != 0
    return Money.new(@amount - (money.convert_to(@currency)).amount, @currency)
  elsif money.amount != 0  #if money.amount == 0 we don't even bother creating a new Money instance
    return Money.new(@amount - money.amount, @currency)
  end
end
/(number) click to toggle source
# File lib/Money_DaWanda/arithmetics.rb, line 25
def /(number)
  raise ArgumentError, 'Number should be a non nil numeric'  unless number.is_a?(Numeric) and number != 0
    return Money.new((@amount / number).round(2), @currency)
end