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
57
|
# File 'lib/smogon/pokedex.rb', line 23
def self.get(name)
begin
url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}"
pokemon = Pokemon.new
smogon = Nokogiri::HTML(open(url))
rescue
return nil
end
pokemon.name = smogon.xpath('//td[@class="header"]/h1').last.text
pokemon._name = pokemon.name.downcase
smogon.xpath('//table[@class="info"]/tr/td/a')[0..-2].each { |type|
(pokemon.types ||= []) << type.text
}
pokemon.tier = smogon.xpath('//table[@class="info"]/tr/td/a').last.text
smogon.xpath('//td[@class="ability"]/dl/dt/a').each { |ability|
(pokemon.abilities ||= []) << ability.text
}
begin
(pokemon.abilities ||= []) << smogon.xpath('//td[@class="ability"]/dl/dt/em/a').first.text
rescue
end
smogon.xpath('//td[@class="bar"]').each { |base_stat|
(pokemon.base_stats ||= []) << base_stat.text.strip
}
return pokemon
end
|