module Monefy::Arithmetic
Encapsulate all the logic to handle basics arithmetic between two instances.
Public Instance Methods
*(value)
click to toggle source
Multiply a Monefy
instances amount
@param value [Integer, Float] value to multiply the Monefy
instance amount.
@return [Monefy] new Monefy
instance with multiplied amount.
@example
Monefy.new(50, 'EUR') * 3 => #<Monefy:0x... @amount=150, @currency="EUR">
# File lib/monefy/arithmetic.rb, line 72 def * value validate_arithmetic_value(value) calculated_amount = amount * value create_new_instace( calculated_amount, currency ) end
+(monefy)
click to toggle source
Sum two Monefy
instances
@param monefy [Monefy] another Monefy
instance.
@return [Monefy] new Monefy
instance with added amount.
@example
Monefy.new(50, 'EUR') + Monefy.new(20, 'USD') => #<Monefy:0x... @amount=68.02, @currency="EUR">
# File lib/monefy/arithmetic.rb, line 14 def + monefy validate_monefy_instance(monefy) calculated_amount = amount + converted_money_currency(monefy) create_new_instace( calculated_amount, currency ) end
-(monefy)
click to toggle source
Subtract two Monefy
instances
@param monefy [Monefy] another Monefy
instance.
@return [Monefy] new Monefy
instance with subtracted amount.
@example
Monefy.new(50, 'EUR') - Monefy.new(20, 'USD') => #<Monefy:0x... @amount=31.98, @currency="EUR">
# File lib/monefy/arithmetic.rb, line 33 def - monefy validate_monefy_instance(monefy) calculated_amount = amount - converted_money_currency(monefy) create_new_instace( calculated_amount, currency ) end
/(value)
click to toggle source
Split a Monefy
instances amount
@param value [Integer, Float] value to split the Monefy
instance amount.
@return [Monefy] new Monefy
instance with splited amount.
@example
Monefy.new(50, 'EUR') / 2 => #<Monefy:0x... @amount=25, @currency="EUR">
# File lib/monefy/arithmetic.rb, line 52 def / value validate_arithmetic_value(value) calculated_amount = amount / value create_new_instace( calculated_amount, currency ) end
Private Instance Methods
validate_arithmetic_value(value)
click to toggle source
# File lib/monefy/arithmetic.rb, line 84 def validate_arithmetic_value(value) return if value.is_a? Numeric raise StandardError, "Not a numeric" end