Class: Smogon::Type::Pokemon

Inherits:
Base
  • Object
show all
Defined in:
lib/smogon/types/pokemon.rb

Constant Summary collapse

ATTRIBUTES =
%w(
  name base_stats weight height types abilities evolutions genfamily moves
).freeze
TYPE =
'pokemon'.freeze
STATS =
%w(hp atk def spa spd spe).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_h, #to_s, #url

Constructor Details

#initialize(response = nil, moves = nil) ⇒ Pokemon

Returns a new instance of Pokemon.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/smogon/types/pokemon.rb', line 32

def initialize(response = nil, moves = nil)
  return unless response

  @name       = response['name']
  @evolutions = response['evos']
  @genfamily  = response['genfamily']

  if moves.include?('Hidden Power Fire')
    moves.delete_if { |move| move.start_with?('Hidden Power ') }
    moves << 'Hidden Power'
  end
  @moves = moves.uniq

  alts = response['alts'][0]
  @base_stats = alts.fetch_values(*STATS)
  @weight     = alts['weight']
  @height     = alts['height']
  @types      = alts['types']
  @abilities  = alts['abilities']
end

Class Method Details

.id2name(id) ⇒ Object



53
54
55
56
# File 'lib/smogon/types/pokemon.rb', line 53

def self.id2name(id)
  response = open("http://pokeapi.co/api/v2/pokemon/#{id}")
  JSON.parse(response.read)['name']
end