Class: Pokemon
- Inherits:
-
Object
- Object
- Pokemon
- Defined in:
- lib/pokemon.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #can_learn_move?(move) ⇒ Boolean
- #get_moves ⇒ Object
-
#initialize(name) ⇒ Pokemon
constructor
A new instance of Pokemon.
Constructor Details
#initialize(name) ⇒ Pokemon
Returns a new instance of Pokemon.
7 8 9 10 11 |
# File 'lib/pokemon.rb', line 7 def initialize(name) @name = name @type = Scraper.get_pokemon_by_name(name)["types"][0]["type"]["name"] @@all << self end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/pokemon.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/pokemon.rb', line 4 def type @type end |
Class Method Details
.all ⇒ Object
21 22 23 |
# File 'lib/pokemon.rb', line 21 def self.all @@all end |
Instance Method Details
#can_learn_move?(move) ⇒ Boolean
17 18 19 |
# File 'lib/pokemon.rb', line 17 def can_learn_move?(move) self.get_moves.collect{|m| m.name}.include?(move.name) end |
#get_moves ⇒ Object
13 14 15 |
# File 'lib/pokemon.rb', line 13 def get_moves Scraper.get_pokemon_by_name(@name)["moves"].collect{|move_hash| Move.new(move_hash["move"]["name"])} end |