Class: PokeAPI::Parser::Pokemon
- Inherits:
-
Object
- Object
- PokeAPI::Parser::Pokemon
- Defined in:
- lib/pokeapi/parser/pokemon.rb
Constant Summary collapse
- ANIMATED_THUMBNAIL_SOURCE =
"http://pokegifs.surge.sh/"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Pokemon
constructor
A new instance of Pokemon.
- #parse ⇒ Object
Constructor Details
#initialize(data) ⇒ Pokemon
Returns a new instance of Pokemon.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pokeapi/parser/pokemon.rb', line 10 def initialize(data) @data = data.clone @abilities = @data.delete :abilities @moves = @data.delete :moves @types = @data.delete :types @stats = @data.delete :stats @thumbnail = @data.delete(:sprites).delete(:front_default) @animated_thumbnail = "#{ANIMATED_THUMBNAIL_SOURCE}#{@data[:id]}.gif" @species_id = @data[:species][:url].split("/").last end |
Class Method Details
.parse(data) ⇒ Object
6 7 8 |
# File 'lib/pokeapi/parser/pokemon.rb', line 6 def self.parse(data) new(data).parse end |
Instance Method Details
#parse ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pokeapi/parser/pokemon.rb', line 21 def parse { id: @data[:id], name: @data[:name], abilities: abilities, moves: moves, types: types, stats: stats, thumbnail: @thumbnail, animated_thumbnail: @animated_thumbnail, species_id: @species_id, } end |