Sha256: 1e02d191571e66815ad1595fc7d1774536290c4b3d7d50afa8a3bb9a619af570

Contents?: true

Size: 759 Bytes

Versions: 16

Compression:

Stored size: 759 Bytes

Contents

#!/usr/bin/env ruby
# CurrencyConverter -- ydim -- 01.02.2006 -- hwyss@ywesee.com

module YDIM
	class MobileCurrencyConverter
		def initialize(conversions={})
			@conversions = conversions
		end
		def convert(amount, origin, target)
			return amount if(origin == target)
			amount.to_f * @conversions.fetch([origin, target]) { 
				raise "Unknown Conversion '#{origin}' -> '#{target}'"
			}
		end
	end
	class CurrencyConverter < MobileCurrencyConverter
		def drb_dup
			MobileCurrencyConverter.new(@conversions)
		end
		def known_currencies
			@conversions.keys.collect { |origin, target| origin }.uniq.size
		end
		def store(origin, target, rate)
			@conversions.store([target, origin], 1.0/rate)
			@conversions.store([origin, target], rate)
		end
	end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ydim-1.1.5 lib/ydim/currency_converter.rb
ydim-1.1.4 lib/ydim/currency_converter.rb
ydim-1.1.3 lib/ydim/currency_converter.rb
ydim-1.1.2 lib/ydim/currency_converter.rb
ydim-1.1.1 lib/ydim/currency_converter.rb
ydim-1.1.0 lib/ydim/currency_converter.rb
ydim-1.0.9 lib/ydim/currency_converter.rb
ydim-1.0.8 lib/ydim/currency_converter.rb
ydim-1.0.7 lib/ydim/currency_converter.rb
ydim-1.0.6 lib/ydim/currency_converter.rb
ydim-1.0.5 lib/ydim/currency_converter.rb
ydim-1.0.4 lib/ydim/currency_converter.rb
ydim-1.0.3 lib/ydim/currency_converter.rb
ydim-1.0.2 lib/ydim/currency_converter.rb
ydim-1.0.1 lib/ydim/currency_converter.rb
ydim-1.0.0 lib/ydim/currency_converter.rb