Class: PollenCounts

Inherits:
Object
  • Object
show all
Defined in:
lib/utahpollen.rb

Constant Summary collapse

LEVEL =
{}

Class Method Summary collapse

Class Method Details

.getObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/utahpollen.rb', line 13

def self.get
  begin
    doc = Nokogiri::HTML(open("http://www.intermountainallergy.com/pollen.html"))
    names = []
    doc.xpath('//td/b').each do |node|
      names << node.text  
    end

    counts = []
    doc.xpath('//td/img').each do |node|
        counts << node[:width] if node[:src] == "images/gl.jpg"
    end

    res = {}
    names.each_with_index do |n,i|
      res[n.lstrip] = LEVEL[counts[i]]
    end
  rescue
    res = {}
  end

  res
end