Class: YDIM::MobileCurrencyConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/ydim/currency_converter.rb

Direct Known Subclasses

CurrencyConverter

Instance Method Summary collapse

Constructor Details

#initialize(conversions = {}) ⇒ MobileCurrencyConverter

Returns a new instance of MobileCurrencyConverter.



6
7
8
# File 'lib/ydim/currency_converter.rb', line 6

def initialize(conversions={})
	@conversions = conversions
end

Instance Method Details

#convert(amount, origin, target) ⇒ Object



9
10
11
12
13
14
# File 'lib/ydim/currency_converter.rb', line 9

def convert(amount, origin, target)
	return amount if(origin == target)
	amount.to_f * @conversions.fetch([origin, target]) { 
		raise "Unknown Conversion '#{origin}' -> '#{target}'"
	}
end