Class: Pokemon::Damage
- Inherits:
-
Object
- Object
- Pokemon::Damage
- Defined in:
- lib/pokemonit.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Damage
constructor
A new instance of Damage.
Constructor Details
#initialize(options) ⇒ Damage
Returns a new instance of Damage.
7 8 9 |
# File 'lib/pokemonit.rb', line 7 def initialize() @name = [:name] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/pokemonit.rb', line 6 def name @name end |
Class Method Details
.all ⇒ Object
11 12 13 14 15 |
# File 'lib/pokemonit.rb', line 11 def self.all data = [] Unirest.get("http://pokeapi.co/api/v2/pokemon/?limit=151").body["results"].map {|pokemon| data << Damage.new(pokemon)} data.map {|pokemon| pokemon.name} end |
.name(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pokemonit.rb', line 17 def self.name(name) data = [] Unirest.get("http://pokeapi.co/api/v2/pokemon/?limit=151").body["results"].map {|pokemon| data << Damage.new(pokemon)} pokemon_names = data.map {|pokemon| pokemon.name} pokemon_index = pokemon_names.index(name) + 1 pokemon_object = self.get_pokemon(pokemon_index) types = self.get_types(pokemon_object) dmg_arr = [] types.each {|type_obj| dmg_arr << self.get_dmg(type_obj)} dmg_arr.unshift(pokemon_names.first) end |