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
|
# File 'lib/smogon/pokedex.rb', line 22
def self.get(name, fields = nil)
incapsulate = fields == nil
fields ||= [
'name',
'alias',
'alts' => [
{ 'types' => %w(name) },
{ 'tags' => %w(shorthand) },
{ 'abilities' => %w(name) },
'hp', 'patk', 'pdef', 'spatk', 'spdef', 'spe'
],
'moves' => ['name']
]
response = API.request 'pokemon', name, fields
return nil if response.is_a?(String) || response.empty? || response.first.empty?
return response if not incapsulate
response = response.first
pokedex = response['alts'][0]
Pokemon.new.tap do |pokemon|
pokemon.name = response['name']
pokemon._name = response['alias']
pokemon.types = pokedex['types'].collect(&:values).flatten
pokemon.tier = pokedex['tags'][0]['shorthand']
pokemon.abilities = pokedex['abilities'].collect(&:values).flatten
pokemon.base_stats = [].tap do |base_stats|
['hp', 'patk', 'pdef', 'spatk', 'spdef', 'spe'].each do |stat|
base_stats << pokedex[stat]
end
end
pokemon.moves = response['moves'].collect(&:values).flatten
end
end
|