Class: Conekta::List
- Inherits:
-
ConektaObject
- Object
- Hash
- ConektaObject
- Conekta::List
- Defined in:
- lib/conekta/list.rb
Instance Attribute Summary collapse
-
#elements_type ⇒ Object
readonly
Returns the value of attribute elements_type.
-
#has_more ⇒ Object
readonly
Returns the value of attribute has_more.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Attributes inherited from ConektaObject
Instance Method Summary collapse
- #add_element(element) ⇒ Object
-
#initialize(elements_type, params) ⇒ List
constructor
A new instance of List.
- #load_from(response) ⇒ Object
- #next(options = {}) ⇒ Object
- #previous(options = {}) ⇒ Object
Methods inherited from ConektaObject
#class_name, class_name, #create_attr, #first, #inspect, #last, #set_val, #to_s, #unset_key
Constructor Details
#initialize(elements_type, params) ⇒ List
Returns a new instance of List.
5 6 7 8 9 10 |
# File 'lib/conekta/list.rb', line 5 def initialize(elements_type, params) super() @elements_type = elements_type @params = (params || {}) @total = 0 end |
Instance Attribute Details
#elements_type ⇒ Object (readonly)
Returns the value of attribute elements_type.
3 4 5 |
# File 'lib/conekta/list.rb', line 3 def elements_type @elements_type end |
#has_more ⇒ Object (readonly)
Returns the value of attribute has_more.
3 4 5 |
# File 'lib/conekta/list.rb', line 3 def has_more @has_more end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/conekta/list.rb', line 3 def params @params end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/conekta/list.rb', line 3 def total @total end |
Instance Method Details
#add_element(element) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/conekta/list.rb', line 12 def add_element(element) element = Conekta::Util.convert_to_conekta_object(element['object'], element) self[@total] = element self.values[@total] = element @total = @total + 1 self end |
#load_from(response) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/conekta/list.rb', line 43 def load_from(response) @has_more = response["has_more"] @total = response["total"] self.map{|key, _| self.unset_key(key) } super(response["data"]) end |
#next(options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/conekta/list.rb', line 23 def next(={}) if self.size > 0 @params["next"] = self.last.id end @params["previous"] = nil move_cursor([:limit]) end |
#previous(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/conekta/list.rb', line 33 def previous(={}) if self.size > 0 @params["previous"] = self.first.id end @params["next"] = nil move_cursor([:limit]) end |