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
54
55
56
|
# File 'lib/smogon/abilitydex.rb', line 22
def self.get(name)
begin
name = name.downcase.gsub /\s/, ?_
url = URI::encode "http://www.smogon.com/bw/abilities/#{name}"
smogon = Nokogiri::HTML(open(url))
rescue
return nil
end
ability = Ability.new
s = smogon.xpath('//div[@id="content_wrapper"]')[0]
ability.name = s.xpath('.//h1').first.text
ability._name = name
ability.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?
}
}
return ability
end
|