Class: Conekta::List

Inherits:
ConektaObject show all
Defined in:
lib/conekta/list.rb

Instance Attribute Summary collapse

Attributes inherited from ConektaObject

#values

Instance Method Summary collapse

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_typeObject (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_moreObject (readonly)

Returns the value of attribute has_more.



3
4
5
# File 'lib/conekta/list.rb', line 3

def has_more
  @has_more
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/conekta/list.rb', line 3

def params
  @params
end

#totalObject (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(options={})
  if self.size > 0
    @params["next"] = self.last.id
  end

  @params["previous"] = nil

  move_cursor(options[:limit])
end

#previous(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/conekta/list.rb', line 33

def previous(options={})
  if self.size > 0
    @params["previous"] = self.first.id
  end

  @params["next"] = nil

  move_cursor(options[:limit])
end