Sha256: 70c11a4e749f29526b3360d001d1e273bb806edecbb905688eaa0daba169aab8
Contents?: true
Size: 784 Bytes
Versions: 4
Compression:
Stored size: 784 Bytes
Contents
module Danconia module Exchanges class Exchange attr_reader :store def initialize store: Stores::InMemory.new @store = store end def rate from, to if from == 'USD' and direct_rate = @store.direct_rate(from, to) direct_rate elsif to == 'USD' and inverse_rate = @store.direct_rate(to, from) (1.0 / inverse_rate).round 6 elsif from != 'USD' and to != 'USD' and from_in_usd = rate(from, 'USD') and to_per_usd = rate('USD', to) (from_in_usd * to_per_usd).round 6 else raise Errors::ExchangeRateNotFound.new(from, to) end end def rates @store.rates end def update_rates! @store.save_rates fetch_rates end end end end
Version data entries
4 entries across 4 versions & 1 rubygems