class Money

Attributes

amount[RW]
currency[RW]

Public Class Methods

conversion_rates(main_currency, hash) click to toggle source
# File lib/MoneyConversion.rb, line 26
def self.conversion_rates(main_currency, hash)
  @@main_currency = main_currency
  @@hash = hash
end
hash() click to toggle source
# File lib/MoneyConversion.rb, line 18
def self.hash
  @@hash
end
main_currency() click to toggle source
# File lib/MoneyConversion.rb, line 14
def self.main_currency
  @@main_currency
end
new(amount, currency) click to toggle source
# File lib/MoneyConversion.rb, line 9
def initialize(amount, currency)
  @currency = currency
  @amount = amount
end

Public Instance Methods

*(factor) click to toggle source
# File lib/MoneyConversion.rb, line 56
def *(factor)
  Money.new(self.amount * factor, self.currency)
end
+(other) click to toggle source
# File lib/MoneyConversion.rb, line 40
def +(other)
  if same_currency(self.currency, other.currency)
    Money.new(self.amount + other.amount, self.currency)
  else
    Money.new(self.amount + other.amount/@@hash[other.currency], self.currency)
  end
end
-(other) click to toggle source
# File lib/MoneyConversion.rb, line 48
def -(other)
  if same_currency(self.currency, other.currency)
    Money.new(self.amount - other.amount, self.currency)
  else
    Money.new(self.amount - other.amount/@@hash[other.currency], self.currency)
  end
end
/(factor) click to toggle source
# File lib/MoneyConversion.rb, line 60
def /(factor)
  Money.new(self.amount / factor, self.currency)
end
<=>(other) click to toggle source
# File lib/MoneyConversion.rb, line 31
def <=> (other)
  if self.currency == other.currency
    self.amount <=> other.amount
  else
    puts (other.amount*(@@hash[other.currency]))
    self.amount <=> (other.amount/(@@hash[other.currency]))
  end
end
convert_to(currency) click to toggle source
# File lib/MoneyConversion.rb, line 22
def convert_to(currency)
  Money.new(@@hash[currency]*@amount  ,currency )
end
same_currency(currency1, currency2) click to toggle source
# File lib/MoneyConversion.rb, line 64
def same_currency(currency1, currency2)
  currency1 == currency2
end