Sha256: dc4d1cb7db1076e47781cd4be36734672761128c9b0c421c34b8f5b2c0371f8e
Contents?: true
Size: 566 Bytes
Versions: 1
Compression:
Stored size: 566 Bytes
Contents
require 'date' require 'bigdecimal/util' module ECB module Exchange VERSION = "0.1.1".freeze def self.convert(amount, from:, to:, date: Date.today) amount.to_d * rate(from: from, to: to, date: date) end def self.rate(from:, to:, date: Date.today) rates = XMLFeed.rates(date) [from, to].each do |currency| raise CurrencyNotFoundError.new(currency) unless rates[currency] end rates[to].to_d * 1.to_d / rates[from].to_d end def self.currencies XMLFeed.rates(Date.today).keys end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ecb_exchange-0.1.1 | lib/ecb/exchange.rb |