class Pokemon

Constants

CONST_GENERATIONS

do not load any pokemon outside of these id #'s

Attributes

abilities[RW]
base_stats[RW]
data[RW]
generation[RW]
height[RW]
id[RW]
moves[RW]
name[RW]
types[RW]
url[RW]
weight[RW]

Public Class Methods

all() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 25
def self.all
    @@all
end
limit() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 37
def self.limit
    @@limit
end
new(name, url) click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 13
def initialize(name, url)
    self.name = name
    self.url = url
    self.data = JSON.parse(RestClient.get(url))
    self.moves = []
    self.abilities = []
    self.types = []
    self.base_stats = []
    self.set_attributes
    @@all << self
end
print_all() click to toggle source
tag() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 33
def self.tag
    @@tag
end

Public Instance Methods

add_ability(ability) click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 106
def add_ability(ability)
    self.abilities << ability
    if !ability.pokemon_with_ability.include?(self)
        ability.add_pokemon(self)
    end
end
add_move(move) click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 99
def add_move(move)
    self.moves << move
    if !move.pokemon_with_move.include?(self)
        move.add_pokemon(self)
    end
end
add_type(type) click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 113
def add_type(type)
    self.types << type
    if !type.pokemon_with_type.include?(self)
        type.add_pokemon(self)
    end
end
get_colored_name() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 147
def get_colored_name
    self.name.capitlize.light_yellow
end
print_abilities() click to toggle source
print_all() click to toggle source
print_base_stats() click to toggle source
print_generation() click to toggle source
print_moves() click to toggle source
print_name() click to toggle source
print_types() click to toggle source
print_weight_and_height() click to toggle source
set_abilities() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 57
def set_abilities
   ability_array = Ability.find_from_array(self.data["abilities"])
   ability_array.each{|ability| self.add_ability(ability)}
end
set_attributes() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 41
def set_attributes
    self.set_moves
    self.set_abilities
    self.set_types
    self.set_id
    self.set_generation
    self.set_height
    self.set_weight
    self.set_base_stats
end
set_base_stats() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 92
def set_base_stats
    stats = self.data["stats"]
    stats.each do |stat|
        self.base_stats << "#{stat["stat"]["name"]}: #{stat["base_stat"]}"
    end
end
set_generation() click to toggle source

set generation by using id number (make constants with generation numbers)

# File lib/dexter_plusplus/pokemon.rb, line 81
def set_generation
    i = 0
    while i < CONST_GENERATIONS.size && self.generation.nil?
        if self.id > CONST_GENERATIONS[i]
            i += 1
        else
            self.generation = i + 1
        end
    end
end
set_height() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 71
def set_height
    self.height = self.data["height"]
end
set_id() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 67
def set_id
    self.id = self.data["id"]
end
set_moves() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 52
def set_moves
    move_array = Move.find_from_array(self.data["moves"].first(4))
    move_array.each{|move| self.add_move(move)}
end
set_types() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 62
def set_types
    type_array = Type.find_from_array(self.data["types"])  
    type_array.each{|type| self.add_type(type)}
end
set_weight() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 75
def set_weight
    self.weight = self.data["weight"]
end
tag() click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 29
def tag
    @@tag
end