Sha256: 999716f274a8ed7947fc37fbdd148df8f79ba86872e2dcb38cf67d5051e51cee
Contents?: true
Size: 597 Bytes
Versions: 1
Compression:
Stored size: 597 Bytes
Contents
# frozen_string_literal: true require 'date' require 'bigdecimal/util' module ECB module Exchange VERSION = "0.2.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.2.1 | lib/ecb/exchange.rb |