Sha256: e506fae602e511a1e9c29f744f16b6e4646d1c7f355caba0de0e46ac46c6e354
Contents?: true
Size: 846 Bytes
Versions: 1
Compression:
Stored size: 846 Bytes
Contents
module Danconia module Exchanges class Exchange attr_reader :store, :currencies def initialize store: Stores::InMemory.new, currencies: [] @store = store @currencies = currencies 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
danconia-0.2.2 | lib/danconia/exchanges/exchange.rb |