module FxPotato

Constants

DATA_FILE
DEFAULT_SOURCE_URL
VERSION

Public Class Methods

at(base_key, target_key, date = nil) click to toggle source
# File lib/fxpotato.rb, line 12
def self.at(base_key, target_key, date = nil)
  base_key = upcase_if_not_nil(base_key)
  target_key = upcase_if_not_nil(target_key)
  date ||= Date.today

  base_rate = RateStore.get(self.repo, date, base_key)
  target_rate = RateStore.get(self.repo, date, target_key)

  FxRate.new(
    base_key,
    base_rate,
    target_key,
    target_rate,
    date,
    RateCalculator.calculate(base_rate, target_rate)
  ).serialize
end
fetch_new_rates() click to toggle source
# File lib/fxpotato.rb, line 30
def self.fetch_new_rates
  data_dir = Paths.data_directory(defined?(Rails))
  Dir.mkdir data_dir if !File.exists? data_dir
  destination = File.join(data_dir, DATA_FILE)
  RateFetcher.fetch(Paths.data_source_url, destination)
end
upcase_if_not_nil(str) click to toggle source
# File lib/fxpotato.rb, line 37
def self.upcase_if_not_nil(str)
  str.nil? || !str.is_a?(String) ? nil : str.upcase
end

Public Instance Methods

repo() click to toggle source
# File lib/fxpotato.rb, line 42
def repo; @repo ||= XmlRepo.new end
repo=(v;) click to toggle source
# File lib/fxpotato.rb, line 43
def repo= v; @repo = v end