class PokeAPI::Parser::Type
Constants
- HEX_COLORS
Public Class Methods
new(data)
click to toggle source
# File lib/pokeapi/parser/type.rb, line 29 def initialize(data) @data = data.clone @damage_relations = @data.delete :damage_relations end
parse(data)
click to toggle source
# File lib/pokeapi/parser/type.rb, line 25 def self.parse(data) new(data).parse end
Public Instance Methods
parse()
click to toggle source
# 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
Private Instance Methods
damage_relations()
click to toggle source
# File lib/pokeapi/parser/type.rb, line 45 def damage_relations @damage_relations.each_with_object({}) do |(damage_relation, types), hsh| hsh[damage_relation] = types.map do |type| { id: type[:url].split("/").last, name: type[:name] } end end end