Class: Grepolis::Api::Base
- Inherits:
-
Object
- Object
- Grepolis::Api::Base
- Defined in:
- lib/grepolis/api/base.rb
Direct Known Subclasses
AllianceKillsAll, AllianceKillsAtt, AllianceKillsDef, Alliances, Conquers, Islands, PlayerKillsAll, PlayerKillsAtt, PlayerKillsDef, Players, Towns
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(conn) ⇒ Base
constructor
A new instance of Base.
- #method_missing(meth, *args) ⇒ Object
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
#conn ⇒ Object (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
#all ⇒ Object
11 12 13 |
# File 'lib/grepolis/api/base.rb', line 11 def all data end |