22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/smogon/itemdex.rb', line 22
def self.get(name)
begin
name = name.downcase.gsub /\s/, ?_
url = URI::encode "http://www.smogon.com/bw/items/#{name}"
smogon = Nokogiri::HTML open(url)
rescue
return nil
end
Item.new.tap { |item|
s = smogon.xpath('//div[@id="content_wrapper"]')[0]
item.name = s.xpath('.//h1').first.text
item._name = name
item.description = ''.tap { |d|
h2 = 0
ul = 0
s.children.each { |c|
if c.name == 'h2'
h2 += 1
next
end
if c.name == 'ul'
ul += 1
next
end
break if ul >= 2
d << c.text if h2 == 1 && !c.text.strip.empty?
}
}
}
end
|