Sha256: 2dfaecf94f5f1f8ecfffb0974038e97ca643ecf0a04d183dd0725ccd5f210c18
Contents?: true
Size: 783 Bytes
Versions: 1
Compression:
Stored size: 783 Bytes
Contents
require 'danconia/stores/in_memory' module Danconia 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 # Currently is only needed for money formatting def available_currencies [] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
danconia-0.2.1 | lib/danconia/exchange.rb |