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
# File lib/dexter_plusplus/pokemon.rb, line 139 def self.print_all self.all.each{|pokemon| pokemon.print_all} end
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
# File lib/dexter_plusplus/pokemon.rb, line 157 def print_abilities output = "\tAbilities:\n" self.abilities.each_with_index{|ability, index| output += "\t\t#{index + 1}: #{ability.get_colored_name}\n"} puts output end
print_all()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 120 def print_all puts "---------------------------------------------------------" puts " Dexter++ : Pokemon ".light_yellow puts "---------------------------------------------------------" self.print_name puts "" self.print_generation self.print_weight_and_height puts "" self.print_types puts "" self.print_abilities puts "" self.print_moves puts "" self.print_base_stats puts "---------------------------------------------------------" end
print_base_stats()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 169 def print_base_stats output = "\tBase Stats:\n" self.base_stats.each{|stat| output += "\t\t#{stat.capitalize}\n"} puts output end
print_generation()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 180 def print_generation puts "\tGeneration: #{self.generation}" end
print_moves()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 163 def print_moves output = "\tMoves:\n" self.moves.each_with_index{|move, index| output += "\t\t#{index + 1}: #{move.get_colored_name}\n"} puts output end
print_name()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 143 def print_name puts "Name: #{self.name.capitalize.light_yellow}" end
print_types()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 151 def print_types output = "\tTypes:\n" self.types.each_with_index{|type, index| output += "\t\t#{index + 1}: #{type.print_name(type.name)}\n"} puts output end
print_weight_and_height()
click to toggle source
# File lib/dexter_plusplus/pokemon.rb, line 175 def print_weight_and_height puts "\tHeight: #{self.height}" puts "\tWeight: #{self.weight}" end
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