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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/smogon/movesetdex.rb', line 22
def self.get(name, tier, metagame)
begin
url = URI::encode "http://www.smogon.com/#{metagame}/pokemon/#{name}/#{tier}"
smogon = Nokogiri::HTML(open(url))
rescue
return nil
end
movesets = []
smogon.xpath('//table[@class="info strategyheader"]').each { |s|
moveset = Moveset.new
moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
s.xpath('.//a').each { |a|
moveset.item << a.text if a['href'].include? '/items/'
moveset.ability << a.text if a['href'].include? '/abilities/'
moveset.nature << a.text if a['href'].include? '/natures/'
}
movesets << moveset
}
i = 0
smogon.xpath('//table[@class="info moveset"]').each { |s|
moveset = movesets[i]
continue = false
s.xpath('.//td')[0].text.each_line { |a|
a = a.gsub(/\n?/, '').strip
if a == ?~
continue = false
elsif a == ?/
continue = true
elsif a.empty?
next
elsif a != ?~ && a != ?/
if continue
moveset.moves.last << a
else
moveset.moves << [a]
end
continue = false
end
}
moveset.evs = s.xpath('.//td').last.text.strip
movesets[i] = moveset
i += 1
}
return movesets
end
|