Sha256: 3bac0f9d3261c07e6a90d093928ac13ac892fad128974b98f6a78fb76aea5bf9

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.2".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.2 lib/ecb/exchange.rb