class FxPotato::XmlRepo

Public Class Methods

new(data = nil) click to toggle source
# File lib/fxpotato/xml_repo.rb, line 5
def initialize(data = nil)
  @data = Nokogiri::XML(data || local_data)
  @data.remove_namespaces!
end

Public Instance Methods

find(date, currency) click to toggle source
# File lib/fxpotato/xml_repo.rb, line 17
def find(date, currency)
  query = "//Cube[@time=\'#{date.to_s}\']//Cube[@currency=\'#{currency}\']"
  result = @data.at_xpath(query)
  result ? result["rate"].to_f : nil
end
local_data() click to toggle source
# File lib/fxpotato/xml_repo.rb, line 10
def local_data
  data_dir = Paths.data_directory(defined?(Rails))
  FxPotato::fetch_new_rates if !File.exists? File.join(data_dir, DATA_FILE)
  source_file = File.join(data_dir, DATA_FILE)
  File.open(source_file)
end