Sha256: 3389344b65962665185d212124f439aa1a0b4090961a87875c8a1afc4c4495e5

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

# encoding: utf-8
require 'open-uri'
require 'nokogiri'
require File.dirname(__FILE__) + '/fixer/cache'

module Fixer
  class << self
    def daily
      get('daily')
    end

    def historical
      get('hist')
    end

    def historical_90
      get('hist-90d')
    end

    private

    def get(type)
      path  = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-#{type}.xml"
      feed  = open(path).read
      doc   = Nokogiri::XML(feed)
      doc.xpath('/gesmes:Envelope/xmlns:Cube/xmlns:Cube', doc.root.namespaces).map do |snapshot|
        {
          :date   => snapshot['time'],
          :rates  => snapshot.xpath('./xmlns:Cube').map do |fx|
            {
              :currency => fx['currency'],
              :rate     => fx['rate']
            }
          end
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fixer-0.2.1 lib/fixer.rb
fixer-0.2.0 lib/fixer.rb