Class: Momm::Feeds::ECB

Inherits:
Object
  • Object
show all
Defined in:
lib/momm/feeds/ecb.rb

Constant Summary collapse

FETCHING_URL =
"http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml".freeze
CURRENCIES =

Hard coded for good

%w{USD JPY BGN CZK DKK GBP HUF LTL PLN RON SEK CHF
NOK HRK RUB TRY AUD BRL CAD CNY HKD IDR ILS INR KRW
MXN MYR NZD PHP SGD THB ZAR}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject

Eager loading the instance of ECB

Returns

self



22
23
24
# File 'lib/momm/feeds/ecb.rb', line 22

def instance
  @instance ||= self.send :new
end

Instance Method Details

#currenciesObject



62
63
64
# File 'lib/momm/feeds/ecb.rb', line 62

def currencies
  CURRENCIES
end

#currency_ratesObject

convert the nokogiri parsed data to array

Returns

looks like [Date.now, currency: :CNY, rate: 1.23 …]



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/momm/feeds/ecb.rb', line 44

def currency_rates
  parsed_content.map do |content|
    date = Date.parse(content["time"])
    cubes = content["Cube"]
    cubes.map do |cube|
      {
        date: date,
        currency: cube["currency"].to_sym,
        rate: cube["rate"].to_f
      }
    end
  end.flatten
end

#fetching_urlObject



58
59
60
# File 'lib/momm/feeds/ecb.rb', line 58

def fetching_url
  FETCHING_URL
end

#parsed_contentObject

Parse the XML data by Nokogiri

Returns

Nokogiri Object



34
35
36
37
# File 'lib/momm/feeds/ecb.rb', line 34

def parsed_content
  # @TODO Refactoring Bad patterns
  HTTParty.get(fetching_url, format: :xml)['Envelope']['Cube']['Cube']
end