Class: MC2P::Paginator
- Inherits:
-
Object
- Object
- MC2P::Paginator
- Defined in:
- lib/base.rb
Overview
Paginator - class used on list requests
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(json_dict, object_item_class, resource) ⇒ Paginator
constructor
- Initializes a paginator Params:
json_dict
- Response from server
object_item_class
- Class to wrapper all the items from results field
resource
-
Resource used to get next and previous items.
- Class to wrapper all the items from results field
- Response from server
- Initializes a paginator Params:
-
#next_list ⇒ Object
Params: Returns: Paginator object with the next items.
-
#previous_list ⇒ Object
Params: Returns: Paginator object with the previous items.
Constructor Details
#initialize(json_dict, object_item_class, resource) ⇒ Paginator
Initializes a paginator Params:
json_dict
-
Response from server
object_item_class
-
Class to wrapper all the items from results field
resource
-
Resource used to get next and previous items
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/base.rb', line 12 def initialize(json_dict, object_item_class, resource) @count = json_dict.fetch('count', 0) @_previous = json_dict.fetch('previous', nil) @_next = json_dict.fetch('next', nil) @results = [] json_dict.fetch('results', []).each do |result| @results.push(object_item_class.new(result, resource)) @resource = resource end end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
4 5 6 |
# File 'lib/base.rb', line 4 def count @count end |
#results ⇒ Object
Returns the value of attribute results.
5 6 7 |
# File 'lib/base.rb', line 5 def results @results end |
Instance Method Details
#next_list ⇒ Object
Params: Returns: Paginator object with the next items
25 26 27 |
# File 'lib/base.rb', line 25 def next_list @_next ? @resource.list(abs_url: @_next) : nil end |
#previous_list ⇒ Object
Params: Returns: Paginator object with the previous items
31 32 33 |
# File 'lib/base.rb', line 31 def previous_list @_previous ? @resource.list(abs_url: @_previous) : nil end |