class DawandaConverter::Money

Public Class Methods

conversion_rates(currency="", hash={}) click to toggle source
# File lib/dawanda_converter/money.rb, line 35
def self.conversion_rates(currency="", hash={})
    @@conversions[currency] = hash unless currency.empty? || hash.empty?
end
new(amount, currency) click to toggle source
# File lib/dawanda_converter/money.rb, line 5
def initialize(amount, currency)
    @amount = ( amount || 0 ) #if nil it just assigns ZERO
    @currency = currency
end

Public Instance Methods

*(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 71
def *(y)
  return "#{self.amount * y} #{self.currency}"
end
+(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 50
def +(y)
  if self.currency != y.currency
     y.convert_to(self.currency)
  end

  return "#{self.amount + y.amount} #{self.currency}"
end
-(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 58
def -(y)
  if self.currency != y.currency
     y.convert_to(self.currency)
  end

  return "#{self.amount - y.amount} #{self.currency}"
end
/(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 66
def /(y)
  return "You cannot devide by ZERO!." if y == 0
  return "#{self.amount / y} #{self.currency}"
end
<(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 80
def <(y)
  if self.currency != y.currency
     y.convert_to(self.currency)
  end
  return true if self.amount < y.amount

  return false
end
==(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 75
def ==(y)
  return true if self.amount == y.amount && self.currency == y.currency
  return false
end
>(y) click to toggle source
# File lib/dawanda_converter/money.rb, line 89
def >(y)
  if self.currency != y.currency
     y.convert_to(self.currency)
  end
  return true if self.amount > y.amount

  return false
end
amount() click to toggle source
# File lib/dawanda_converter/money.rb, line 10
def amount
    @amount
end
amount=(amount) click to toggle source
# File lib/dawanda_converter/money.rb, line 22
def amount=(amount)
    @amount = (amount || 0 )
end
conversions() click to toggle source
# File lib/dawanda_converter/money.rb, line 30
def conversions
  @@conversions
end
convert_to(currency) click to toggle source
# File lib/dawanda_converter/money.rb, line 39
def convert_to(currency)
   unless @@conversions.empty? || @@conversions[self.currency].nil?
     self.amount = @@conversions[self.currency][currency].to_f * self.amount
     self.currency = currency
   else
     puts "You must initialize conversion rates first."
   end
end
currency() click to toggle source
# File lib/dawanda_converter/money.rb, line 14
def currency
    @currency
end
currency=(currency) click to toggle source
# File lib/dawanda_converter/money.rb, line 18
def currency=(currency)
    @currency = currency
end
inspect() click to toggle source
# File lib/dawanda_converter/money.rb, line 26
def inspect
   "#{@amount} #{@currency}"
end