Class: PokeAPI::Parser::Type

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

Constant Summary collapse

HEX_COLORS =
{
  normal: '#A8A878',
  fire: '#F08030',
  fighting: '#C03028',
  water: '#6890F0',
  flying: '#A890F0',
  grass: '#78C850',
  poison: '#A040A0',
  electric: '#F8D030',
  ground: '#E0C068',
  psychic: '#F85888',
  rock: '#B8A038',
  ice: '#98D8D8',
  bug: '#A8B820',
  dragon: '#7038F8',
  ghost: '#705898',
  dark: '#705848',
  steel: '#B8B8D0',
  fairy: '#EE99AC'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Type

Returns a new instance of Type.



29
30
31
32
# File 'lib/pokeapi/parser/type.rb', line 29

def initialize(data)
  @data = data.clone
  @damage_relations = @data.delete :damage_relations
end

Class Method Details

.parse(data) ⇒ Object



25
26
27
# File 'lib/pokeapi/parser/type.rb', line 25

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

Instance Method Details

#parseObject



34
35
36
37
38
39
40
41
# File 'lib/pokeapi/parser/type.rb', line 34

def parse
  {
    id: @data[:id],
    name: @data[:name],
    color_hex: HEX_COLORS[@data[:name].to_sym],
    damage_relations: damage_relations
  }
end