Class: CoinSync::CurrencyConverters::Base
- Inherits:
-
Object
- Object
- CoinSync::CurrencyConverters::Base
- Defined in:
- lib/coinsync/currency_converters/base.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #convert(amount, from:, to:, time:) ⇒ Object
- #finalize ⇒ Object
- #get_conversion_rate(from:, to:, time:) ⇒ Object
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
Constructor Details
Class Method Details
.register_converter(key) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/coinsync/currency_converters/base.rb', line 13 def self.register_converter(key) if CurrencyConverters.registered[key] raise "Currency converter has already been registered at '#{key}'" else CurrencyConverters.registered[key] = self end end |
Instance Method Details
#convert(amount, from:, to:, time:) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/coinsync/currency_converters/base.rb', line 26 def convert(amount, from:, to:, time:) (amount > 0) or raise "#{self.class}: amount should be positive" (amount.is_a?(BigDecimal)) or raise "#{self.class}: 'amount' should be a BigDecimal" rate = get_conversion_rate(from: from, to: to, time: time) rate * amount end |
#finalize ⇒ Object
39 40 41 |
# File 'lib/coinsync/currency_converters/base.rb', line 39 def finalize @cache.save end |
#get_conversion_rate(from:, to:, time:) ⇒ Object
35 36 37 |
# File 'lib/coinsync/currency_converters/base.rb', line 35 def get_conversion_rate(from:, to:, time:) raise "not implemented" end |