module CurrencyConverterGemNichohelmut
Constants
- VERSION
Public Class Methods
conversion_rates(fx = {})
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 9 def self.conversion_rates(fx = {}) {'EUR'=>{'USD'=>1.2, 'Bitcoin'=>0.0047}, 'USD'=>{'EUR'=>0.8, 'Bitcoin'=>0.0097}, 'Bitcoin'=>{'USD'=>1.11, 'EUR'=>0.0047}} end
new(amount, curr)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 4 def initialize(amount, curr) @amount = amount @curr = curr end
Public Instance Methods
*(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 46 def *(other) Money.new(self.amount * other, self.curr) end
+(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 38 def +(other) Money.new(self.amount + other.convert_to(self.curr).amount, self.curr) end
-(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 42 def -(other) Money.new(self.amount - other.convert_to(self.curr).amount, self.curr) end
/(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 50 def /(other) Money.new(self.amount / other, self.curr) end
<(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 62 def <(other) self.amount < other.convert_to(self.curr).amount end
==(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 54 def ==(other) self.amount == other.convert_to(self.curr).amount end
>(other)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 58 def >(other) self.amount > other.convert_to(self.curr).amount end
amount()
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 15 def amount @amount end
convert_to(to_curr)
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 27 def convert_to(to_curr) if to_curr != self.curr @rate = Money.conversion_rates[self.curr][to_curr] Money.new(@amount * @rate, to_curr) else Money.new(@amount, curr) end end
curr()
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 19 def curr @curr end
inspect()
click to toggle source
# File lib/currency_converter_gem_nichohelmut.rb, line 23 def inspect '%.2f' % @amount.to_s + " " + @curr end