Class: Alula::ListObject
- Inherits:
-
Object
- Object
- Alula::ListObject
- Includes:
- Enumerable
- Defined in:
- lib/alula/list_object.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#rate_limit ⇒ Object
Returns the value of attribute rate_limit.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .construct_from_array(klass, collection) ⇒ Object
- .construct_from_response(klass, response, opts) ⇒ Object
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #[](index) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(list_type) ⇒ ListObject
constructor
A new instance of ListObject.
- #last ⇒ Object
- #length ⇒ Object
- #pagination ⇒ Object
- #set_meta(meta) ⇒ Object
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
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'lib/alula/list_object.rb', line 5 def items @items end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/alula/list_object.rb', line 5 def @meta end |
#rate_limit ⇒ Object
Returns the value of attribute rate_limit.
6 7 8 |
# File 'lib/alula/list_object.rb', line 6 def rate_limit @rate_limit end |
#type ⇒ Object (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. 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 |
#each ⇒ Object
17 18 19 |
# File 'lib/alula/list_object.rb', line 17 def each items.each { |i| yield i } end |
#first ⇒ Object
25 26 27 |
# File 'lib/alula/list_object.rb', line 25 def first @items.first end |
#last ⇒ Object
29 30 31 |
# File 'lib/alula/list_object.rb', line 29 def last @items.last end |
#length ⇒ Object
13 14 15 |
# File 'lib/alula/list_object.rb', line 13 def length items.length end |
#pagination ⇒ Object
41 42 43 |
# File 'lib/alula/list_object.rb', line 41 def pagination .page end |
#set_meta(meta) ⇒ Object
37 38 39 |
# File 'lib/alula/list_object.rb', line 37 def () @meta = end |