Module: DataFetcher

Defined in:
lib/fafx/data_fetcher.rb

Class Method Summary collapse

Class Method Details

.process_currencies_xml(doc) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fafx/data_fetcher.rb', line 15

def process_currencies_xml(doc)
  rates = {}
  doc.css('Cube>Cube[time]').each do |day|
    time = day[:time]
    rates[time] = {}
    day.css('Cube').each do |currency|
      rates[time][currency[:currency]] = currency[:rate].to_f
    end
  end
  rates
end

.save_to_diskObject



5
6
7
8
9
10
11
# File 'lib/fafx/data_fetcher.rb', line 5

def save_to_disk
  url = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'
  doc = Nokogiri::XML(open(url))
  rates = process_currencies_xml(doc)
  dir = "#{File.join(File.dirname(__FILE__))}/rates.yaml"
  File.open(dir, 'w') { |f| f << rates.to_yaml }
end