class CoinSync::CurrencyConverters::Base
Public Class Methods
new(options)
click to toggle source
# File lib/coinsync/currency_converters/base.rb, line 21 def initialize(options) @options = options @cache = Cache.new(self.class.name.downcase.split('::').last) end
register_converter(key)
click to toggle source
# 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
Public Instance Methods
convert(amount, from:, to:, time:)
click to toggle source
# 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()
click to toggle source
# File lib/coinsync/currency_converters/base.rb, line 39 def finalize @cache.save end
get_conversion_rate(from:, to:, time:)
click to toggle source
# File lib/coinsync/currency_converters/base.rb, line 35 def get_conversion_rate(from:, to:, time:) raise "not implemented" end