Class: PokeAPI::Parser::Species

Inherits:
Object
  • Object
show all
Defined in:
lib/pokeapi/parser/species.rb

Constant Summary collapse

HEX_COLORS =
{
  red: '#f05868',
  blue: '#3088f0',
  yellow: '#f0d048',
  green: '#40b868',
  black: '#585858',
  brown: '#b07030',
  purple: '#a868c0',
  gray: '#a0a0a0',
  white: '#f0f0f0',
  pink: '#f890c8',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Species

Returns a new instance of Species.



21
22
23
24
25
# File 'lib/pokeapi/parser/species.rb', line 21

def initialize(data)
  @data = data.clone
  @flavor_text_entries = @data.delete :flavor_text_entries
  @color_name = @data[:color][:name]
end

Class Method Details

.parse(data) ⇒ Object



17
18
19
# File 'lib/pokeapi/parser/species.rb', line 17

def self.parse(data)
  new(data).parse
end

Instance Method Details

#parseObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/pokeapi/parser/species.rb', line 27

def parse
  {
    id: @data[:id],
    color_name: @color_name,
    color_hex: HEX_COLORS[@color_name.to_sym],
    shape: @data[:shape][:name],
    flavor_text_entries: flavor_text_entries,
    evolution_chain_id: @data[:evolution_chain][:url].split("/").last,
  }
end