Class: Grepolis::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/grepolis/api/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/grepolis/api/base.rb', line 6

def initialize(conn)
  @conn = conn
  @index = {}.tap {|index| self.class::MAPPING.each{|column| index[column] = {}}}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/grepolis/api/base.rb', line 15

def method_missing(meth, *args)
  meth = meth.to_s
  regex = /find_by_/
  column = meth.gsub(regex, '').to_sym
  if meth =~ regex and data and @index[column]
    @index[column][args[0]]
  else
    super
  end
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



4
5
6
# File 'lib/grepolis/api/base.rb', line 4

def conn
  @conn
end

Instance Method Details

#allObject



11
12
13
# File 'lib/grepolis/api/base.rb', line 11

def all
  data
end