class Pokemon

Attributes

atk[RW]
base_stats[RW]
def[RW]
hp[RW]
ivs[RW]
level[RW]
name[RW]
nature[RW]
spa[RW]
spd[RW]
spe[RW]

Public Class Methods

new(name) click to toggle source
# File lib/pokemon.rb, line 10
def initialize(name)
  @name = name.capitalize
end

Public Instance Methods

check_ivs() click to toggle source
# File lib/pokemon.rb, line 14
def check_ivs
  calculator = IVCalculator.new(name, nature, level, hp, atk, self.def, spa, spd, spe, base_stats)
  @ivs = calculator.calculate_ivs
end
gather_pokedex_data() click to toggle source
# File lib/pokemon.rb, line 19
def gather_pokedex_data
  uri = URI("https://pokeapi.co/api/v2/pokemon/#{name.downcase}")
  response = JSON.parse(Net::HTTP.get(uri), symbolize_names: true)
  
  @base_stats = {
    hp:  response[:stats][0][:base_stat],
    atk: response[:stats][1][:base_stat],
    def: response[:stats][2][:base_stat],
    spa: response[:stats][3][:base_stat],
    spd: response[:stats][4][:base_stat],
    spe: response[:stats][5][:base_stat]
  }
rescue JSON::ParserError
  raise PokemonDoesNotExistError, "#{name} does not exist, are you sure you entered it correctly?"
end
print_ivs() click to toggle source