Class: Alula::ListObject

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/alula/list_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_type) ⇒ ListObject

Returns a new instance of ListObject.



8
9
10
11
# File 'lib/alula/list_object.rb', line 8

def initialize list_type
  @type = list_type
  @items = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



5
6
7
# File 'lib/alula/list_object.rb', line 5

def items
  @items
end

#metaObject (readonly)

Returns the value of attribute meta.



5
6
7
# File 'lib/alula/list_object.rb', line 5

def meta
  @meta
end

#rate_limitObject

Returns the value of attribute rate_limit.



6
7
8
# File 'lib/alula/list_object.rb', line 6

def rate_limit
  @rate_limit
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/alula/list_object.rb', line 5

def type
  @type
end

Class Method Details

.construct_from_array(klass, collection) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/alula/list_object.rb', line 56

def self.construct_from_array klass, collection
  list = ListObject.new(klass)
  collection.each do |item|
    list << klass.new(item['id']).construct_from(item)
  end
  list
end

.construct_from_response(klass, response, opts) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/alula/list_object.rb', line 45

def self.construct_from_response klass, response, opts
  list = ListObject.new(klass)
  response.data['data'].each do |item|
    list << klass.new(item['id']).construct_from(item)
  end
  list.set_meta Meta.new(response.data['meta'])
  list.rate_limit = response.rate_limit
  
  list
end

Instance Method Details

#<<(item) ⇒ Object



33
34
35
# File 'lib/alula/list_object.rb', line 33

def << item
  @items << item
end

#[](index) ⇒ Object



21
22
23
# File 'lib/alula/list_object.rb', line 21

def[] index
  @items[index]
end

#eachObject



17
18
19
# File 'lib/alula/list_object.rb', line 17

def each
  items.each { |i| yield i }
end

#firstObject



25
26
27
# File 'lib/alula/list_object.rb', line 25

def first
  @items.first
end

#lastObject



29
30
31
# File 'lib/alula/list_object.rb', line 29

def last
  @items.last
end

#lengthObject



13
14
15
# File 'lib/alula/list_object.rb', line 13

def length
  items.length
end

#paginationObject



41
42
43
# File 'lib/alula/list_object.rb', line 41

def pagination
  meta.page
end

#set_meta(meta) ⇒ Object



37
38
39
# File 'lib/alula/list_object.rb', line 37

def set_meta(meta)
  @meta = meta
end