Class: Danconia::Exchanges::Exchange
- Inherits:
-
Object
- Object
- Danconia::Exchanges::Exchange
show all
- Defined in:
- lib/danconia/exchanges/exchange.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(store: Stores::InMemory.new) ⇒ Exchange
Returns a new instance of Exchange.
8
9
10
|
# File 'lib/danconia/exchanges/exchange.rb', line 8
def initialize store: Stores::InMemory.new
@store = store
end
|
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
6
7
8
|
# File 'lib/danconia/exchanges/exchange.rb', line 6
def store
@store
end
|
Instance Method Details
#rate(from, to) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/danconia/exchanges/exchange.rb', line 12
def rate from, to
return 1.0 if from == to
pair = Pair.new(from, to)
rates = direct_and_inverted_rates()
rates[pair] or indirect_rate(pair, rates) or raise Errors::ExchangeRateNotFound.new(from, to)
end
|
#rates ⇒ Object
20
21
22
|
# File 'lib/danconia/exchanges/exchange.rb', line 20
def rates
@store.rates
end
|
#update_rates! ⇒ Object
24
25
26
|
# File 'lib/danconia/exchanges/exchange.rb', line 24
def update_rates!
@store.save_rates fetch_rates
end
|