Class: CoinSync::Config::CurrencyConversionOptions

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/coinsync/config.rb

Constant Summary collapse

DEFAULT_CURRENCY_CONVERTER =
:exchangeratesapi

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CurrencyConversionOptions

Returns a new instance of CurrencyConversionOptions.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/coinsync/config.rb', line 96

def initialize(options)
  super

  if options['using']
    self.currency_converter_name = options['using'].to_sym
  else
    self.currency_converter_name = DEFAULT_CURRENCY_CONVERTER
  end

  if options['to']
    self.currency = FiatCurrency.new(options['to'].upcase)
  else
    raise "'convert_currency' requires a 'to' field with a currency code"
  end
end

Instance Method Details

#currency_converterObject



112
113
114
115
116
117
118
119
120
# File 'lib/coinsync/config.rb', line 112

def currency_converter
  currency_converter_class = CurrencyConverters.registered[currency_converter_name]

  if currency_converter_class
    currency_converter_class.new(self)
  else
    raise "Unknown currency converter: #{currency_converter_name}"
  end
end