Sha256: 7a77d47ddf376d8c17725a5ca608655540af1ffa5b6417943644500540056e09
Contents?: true
Size: 704 Bytes
Versions: 4
Compression:
Stored size: 704 Bytes
Contents
require 'open-uri' require 'nokogiri' # Europe Gem module Europe # currency module Currency # exchange rates module ExchangeRates EXCHANGE_URL = 'http://www.ecb.europa.eu/stats/' \ 'eurofxref/eurofxref-daily.xml' def self.retrieve extract_rates(Nokogiri::XML(open(EXCHANGE_URL))) end private def self.extract_rates(doc) rates = { date: Date.parse(doc.css('Cube Cube').first['time']), rates: {} } doc.css('Cube Cube Cube').each do |rate| rates[:rates][rate.xpath('@currency').text.to_sym] = rate.xpath('@rate').text.to_f end rates end end end end
Version data entries
4 entries across 4 versions & 1 rubygems