10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/kurs.rb', line 10
def self.refresh
@@kurs = {}
%w{EUR USD CHF GBP}.each do |valuta|
doc = Hpricot(open("http://www.kursna-lista.com/kursne-liste-banaka-i-menjacnica?valuta=#{valuta}"))
(doc/'#curFullTable tr').each do |tr|
banka = (tr/'td:nth(0)').inner_text.gsub(/\s*a.d.|\s*Beograd|\s*Srbija/, '')
next if banka.empty? || banka =~ /Menja/
@@kurs[banka] ||= {}
@@kurs[banka]['kupovni'] ||= {}
@@kurs[banka]['srednji'] ||= {}
@@kurs[banka]['prodajni'] ||= {}
@@kurs[banka]['kupovni'][valuta] = (tr/'td:nth(1)').inner_text.to_f
@@kurs[banka]['srednji'][valuta] = (tr/'td:nth(2)').inner_text.to_f
@@kurs[banka]['prodajni'][valuta] = (tr/'td:nth(3)').inner_text.to_f
@@kurs[banka]['datum'] = (tr/'td:nth(5)').inner_text
end
end
end
|