Class: Smogon::Type::Base
- Inherits:
-
Object
- Object
- Smogon::Type::Base
show all
- Defined in:
- lib/smogon/types/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(response = nil) ⇒ Base
Returns a new instance of Base.
23
24
25
26
27
28
29
|
# File 'lib/smogon/types/base.rb', line 23
def initialize(response = nil)
return unless response
attributes.each do |attr|
public_send("#{attr}=", response[attr])
end
end
|
Instance Method Details
#to_h ⇒ Object
31
32
33
34
35
|
# File 'lib/smogon/types/base.rb', line 31
def to_h
attributes.zip(
attributes.map { |attr| public_send(attr) }
).to_h
end
|
#to_s ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/smogon/types/base.rb', line 37
def to_s
attributes.map do |attr|
key = attr.capitalize.gsub('_', ' ')
val = public_send(attr)
val = val.join(', ') if val.is_a?(Array)
val == '' ? nil : "#{key}: #{val}"
end.compact.join("\n")
end
|
#url ⇒ Object
46
47
48
|
# File 'lib/smogon/types/base.rb', line 46
def url
"http://www.smogon.com/dex/#{::Smogon::API::METAGAME}/#{self.class::TYPE}/#{name}"
end
|