Class: CurrencyRates::Parser
- Inherits:
-
Object
- Object
- CurrencyRates::Parser
- Defined in:
- lib/currency_rates.rb
Constant Summary collapse
- XML_URL =
"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"
Instance Method Summary collapse
- #engage ⇒ Object
-
#initialize(base_currency) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(base_currency) ⇒ Parser
Returns a new instance of Parser.
12 13 14 |
# File 'lib/currency_rates.rb', line 12 def initialize(base_currency) @base_currency = base_currency end |
Instance Method Details
#engage ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/currency_rates.rb', line 16 def engage doc = Nokogiri::XML(open(XML_URL)) currency_collection = doc.css("Cube > Cube > Cube") # Just return if the base currency is EUR as that is # the format of the xml in the firstplace. return to_hash(currency_collection) if @base_currency == 'EUR' rate = get_rate(currency_collection, @base_currency) converted_rates = convert_rates(currency_collection, rate) return to_hash(converted_rates) << euro_rate(rate) end |