Class: Momm::Feeds::ECB
- Inherits:
-
Object
- Object
- Momm::Feeds::ECB
- 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 ⇒ Object
Eager loading the instance of ECB.
Instance Method Summary collapse
- #currencies ⇒ Object
-
#currency_rates ⇒ Object
convert the nokogiri parsed data to array.
- #fetching_url ⇒ Object
-
#parsed_content ⇒ Object
Parse the XML data by Nokogiri == Returns Nokogiri Object.
Class Method Details
.instance ⇒ Object
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
#currencies ⇒ Object
62 63 64 |
# File 'lib/momm/feeds/ecb.rb', line 62 def currencies CURRENCIES end |
#currency_rates ⇒ Object
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_url ⇒ Object
58 59 60 |
# File 'lib/momm/feeds/ecb.rb', line 58 def fetching_url FETCHING_URL end |
#parsed_content ⇒ Object
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 |