Sha256: 4df3639b70b75a75f17fe4139caae9c8b01a8490b048bd31ad53b4f8353ec022
Contents?: true
Size: 696 Bytes
Versions: 4
Compression:
Stored size: 696 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'.freeze def self.retrieve extract_rates(Nokogiri::XML(open(EXCHANGE_URL))) end 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