Class: Smogon::Type::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/smogon/types/base.rb

Direct Known Subclasses

Ability, Item, Move, Moveset, Pokemon

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



23
24
25
26
27
# File 'lib/smogon/types/base.rb', line 23

def initialize(response)
  attributes.each do |attr|
    public_send("#{attr}=", response[attr])
  end
end

Instance Method Details

#to_hObject



29
30
31
32
33
# File 'lib/smogon/types/base.rb', line 29

def to_h
  attributes.zip(
    attributes.map { |attr| public_send(attr) }
  ).to_h
end

#to_sObject



35
36
37
38
39
# File 'lib/smogon/types/base.rb', line 35

def to_s
  attributes.map do |attr|
    "#{attr.capitalize}: #{public_send(attr)}"
  end.join("\n")
end

#urlObject



41
42
43
# File 'lib/smogon/types/base.rb', line 41

def url
  "http://www.smogon.com/dex/#{::Smogon::API::METAGAME}/#{self.class::TYPE}/#{name}"
end