class SimpleExchangeRate::Database
Public Class Methods
new(file = File.open(DATABASE_FILE))
click to toggle source
# File lib/simple_exchange_rate/database.rb, line 11 def initialize(file = File.open(DATABASE_FILE)) @file = Nokogiri::XML(file) @file.remove_namespaces! end
Public Instance Methods
all()
click to toggle source
# File lib/simple_exchange_rate/database.rb, line 16 def all daily_rates.reduce({}) do |all_rates, daily_rate| day = daily_rate.attributes['time'].value all_rates[day] = rates_details(daily_rate) all_rates end end
Private Instance Methods
daily_rates()
click to toggle source
# File lib/simple_exchange_rate/database.rb, line 28 def daily_rates @file.xpath('//Cube[not(@*)]').xpath('Cube') end
rates_details(rate)
click to toggle source
# File lib/simple_exchange_rate/database.rb, line 32 def rates_details(rate) entries = rate.xpath('Cube') entries.reduce({}) do |all_entries, entry| all_entries[entry[:currency]] = entry[:rate] all_entries end end