class Fxer::Exchange::DataSource

Public Class Methods

new(opts = {}) click to toggle source

initialize accepts one optional argument,

1. a hash of options which will be passed to whichever data source
   the user has indicated (i.e. Fxer::Exchange::DataSource::Ecb).
# File lib/fxer/exchange/data_source.rb, line 17
def initialize(opts = {})
  @options = opts
end

Public Instance Methods

exchange(date, base, counter, source) click to toggle source

exchange takes 4 required arguments and returns the data required to determine an exchange value. Arguments are defined in Fxer::Exchange.

# File lib/fxer/exchange/data_source.rb, line 25
def exchange(date, base, counter, source)
  fetch_rates(source).at(date).from(base).to(counter).rates
end

Private Instance Methods

fetch_rates(source) click to toggle source

fetch_rates takes one argument,

1. a symbol represnting a source's corresponding class name.
   Source symbols are defined in Fxer::Exchange.

fetch_rates converts the source of data indicated by the user, i.e. :ecb, (which has been sanitized during configuration), and converts that to a subclass of DataSource, providing options and returning a set of rates, represented by an Fxer::Exchange::Data object.

# File lib/fxer/exchange/data_source.rb, line 42
def fetch_rates(source)
  klass_name = "#{source}".downcase.capitalize
  Object.const_get("Fxer::Exchange::DataSource::#{klass_name}").new(@options).rate_set
end