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