class Pokemon

Attributes

abilities[R]
id[R]
moves[R]
name[R]
raw_data[R]
stats[R]
types[R]
weight[R]

Public Class Methods

catch(pokemon_input) click to toggle source
# File lib/pokemon_lookup.rb, line 23
def self.catch(pokemon_input)
  begin
    new(pokemon_input)
  rescue HTTP::Error
    puts "Unkown Pokemon, try catching a different Pokemon"
    nil
  end
end
new(pokemon_input) click to toggle source
# File lib/pokemon_lookup.rb, line 8
def initialize(pokemon_input)
    sanitized_input = pokemon_input.to_s.downcase
    response = HTTP.get("https://pokeapi.co/api/v2/pokemon/#{ sanitized_input }")
    @raw_data = response.parse

    @id = @raw_data["id"]
    @name = @raw_data["name"].capitalize
    @weight = @raw_data["weight"]
    @types = format_types
    @abilities = format_abilities
    @moves = format_moves
    @stats = format_stats

end
print_list(page=1, amount=20) click to toggle source
terminal_width() click to toggle source
# File lib/pokemon_lookup.rb, line 85
def self.terminal_width
  @@terminal_width
end
terminal_width=(new_terminal_width) click to toggle source
# File lib/pokemon_lookup.rb, line 89
def self.terminal_width=(new_terminal_width)
  @@terminal_width = new_terminal_width
end

Public Instance Methods

print_abilities() click to toggle source
print_info() click to toggle source
print_moves() click to toggle source
print_stats() click to toggle source
print_types() click to toggle source

Private Instance Methods

format_abilities() click to toggle source
# File lib/pokemon_lookup.rb, line 112
def format_abilities
  raw_data["abilities"].map { |ability_hash| ability_hash["ability"]["name"] }
end
format_moves() click to toggle source
# File lib/pokemon_lookup.rb, line 116
def format_moves
  raw_data["moves"].map { |move_hash| move_hash["move"]["name"] }.sort
end
format_stats() click to toggle source
# File lib/pokemon_lookup.rb, line 120
def format_stats
  raw_data["stats"].map do |stats_hash| 
    {
     name: stats_hash["stat"]["name"],
     effort: stats_hash["effort"],
     base_stat: stats_hash["base_stat"]
    }
  end
end
format_types() click to toggle source
# File lib/pokemon_lookup.rb, line 108
def format_types
  raw_data["types"].map { |type_hash| type_hash["type"]["name"] }
end