Class: LoL::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/captainteemo/resource.rb

Direct Known Subclasses

Player

Constant Summary collapse

@@endpoints =
{}
@@endpoint_id =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



33
34
35
36
37
38
39
# File 'lib/captainteemo/resource.rb', line 33

def initialize(attributes={})
  attributes.each do |key, value|
    if self.respond_to?(key.to_sym)
      self.instance_variable_set("@#{key}", value)
    end
  end
end

Class Method Details

.endpoint_idObject



18
19
20
# File 'lib/captainteemo/resource.rb', line 18

def self.endpoint_id
  @@endpoint_id[self.name.downcase]
end

.endpointsObject



14
15
16
# File 'lib/captainteemo/resource.rb', line 14

def self.endpoints
  @@endpoints[self.name.downcase]
end

.has_resource(singular = nil, opts = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/captainteemo/resource.rb', line 6

def self.has_resource(singular=nil, opts={})
  @@endpoints[self.name.downcase] = { 
    :singular => singular.nil? ? "#{self.name.downcase}" : singular, 
    :plural => opts[:plural].nil? ? "#{self.name.downcase}s" : opts[:plural]
  }
  @@endpoint_id[self.name.downcase] = opts[:id].nil? ? "" : "#{opts[:id]}-"
end

.search(platform, query) ⇒ Object Also known as: find



22
23
24
25
26
27
# File 'lib/captainteemo/resource.rb', line 22

def self.search(platform, query)
  search = LoL::Search.new
  search.resource("#{self.endpoints[:singular]}")
  search.query(platform, query)
  self.new(search.fetch)
end