class YDIM::CurrencyUpdater
Public Class Methods
new(serv)
click to toggle source
# File lib/ydim/currency_updater.rb, line 8 def initialize(serv) @serv = serv end
Public Instance Methods
extract_conversion(html)
click to toggle source
# File lib/ydim/currency_updater.rb, line 20 def extract_conversion(html) if(match = /1\s+[^<>=]+=\s+(\d+\.\d+)/.match(html)) match[1] end end
get_conversion(origin, target)
click to toggle source
# File lib/ydim/currency_updater.rb, line 25 def get_conversion(origin, target) extract_conversion(get_html(origin, target)).to_f end
get_html(origin, target)
click to toggle source
# File lib/ydim/currency_updater.rb, line 28 def get_html(origin, target) ## not in test-suite, test manually when modified Net::HTTP.start('www.google.com') { |session| session.get("/search?q=1+#{origin.upcase}+in+#{target.upcase}").body } end
run()
click to toggle source
# File lib/ydim/currency_updater.rb, line 11 def run curr = @serv.config.currencies.dup while(origin = curr.shift) curr.each { |target| update_conversion(origin, target) } end @serv.currency_converter.odba_store end
update_conversion(origin, target)
click to toggle source
# File lib/ydim/currency_updater.rb, line 34 def update_conversion(origin, target) @serv.currency_converter.store(origin, target, get_conversion(origin, target)) end