module Konvert::Operations
Public Instance Methods
*(operand)
click to toggle source
# File lib/operations.rb, line 28 def *(operand) Money.new(self.amount * operand, self.currency) end
+(operand)
click to toggle source
# File lib/operations.rb, line 20 def +(operand) perform_sum(self,operand,'add') end
-(operand)
click to toggle source
# File lib/operations.rb, line 24 def -(operand) perform_sum(self,operand,'subtract') end
/(operand)
click to toggle source
# File lib/operations.rb, line 32 def /(operand) Money.new(self.amount / operand, self.currency) end
<(operand)
click to toggle source
# File lib/operations.rb, line 46 def <(operand) return self.convert_to_base_amount < operand.convert_to_base_amount end
==(operand)
click to toggle source
Comparisons
# File lib/operations.rb, line 38 def ==(operand) return self.convert_to_base_amount == operand.convert_to_base_amount end
>(operand)
click to toggle source
# File lib/operations.rb, line 42 def >(operand) return self.convert_to_base_amount > operand.convert_to_base_amount end
add(val1,val2)
click to toggle source
# File lib/operations.rb, line 12 def add(val1,val2) val1 + val2 end
perform_sum(operand1,operand2,operation)
click to toggle source
# File lib/operations.rb, line 4 def perform_sum(operand1,operand2,operation) amount1 = operand1.convert_to_base_amount amount2 = operand2.convert_to_base_amount sum_in_base_currency = send(operation, amount1, amount2) result = Money.new(sum_in_base_currency, Money.base_currency) operand1.currency == Money.base_currency ? result : result.convert_to(operand1.currency) end
subtract(val1,val2)
click to toggle source
# File lib/operations.rb, line 16 def subtract(val1,val2) val1 - val2 end