Class: Hudu::RequestPagination::PagingInfoPager
- Inherits:
-
Object
- Object
- Hudu::RequestPagination::PagingInfoPager
- Defined in:
- lib/hudu/pagination.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page_size) ⇒ PagingInfoPager
constructor
A new instance of PagingInfoPager.
- #more_pages? ⇒ Boolean
- #next_page!(body) ⇒ Object
- #page_options ⇒ Object
Constructor Details
#initialize(page_size) ⇒ PagingInfoPager
Returns a new instance of PagingInfoPager.
12 13 14 15 |
# File 'lib/hudu/pagination.rb', line 12 def initialize(page_size) @page = 1 @page_total = @page_size = page_size end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
11 12 13 |
# File 'lib/hudu/pagination.rb', line 11 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
11 12 13 |
# File 'lib/hudu/pagination.rb', line 11 def offset @offset end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
11 12 13 |
# File 'lib/hudu/pagination.rb', line 11 def total @total end |
Class Method Details
.data(body) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/hudu/pagination.rb', line 32 def self.data(body) # assume hash {"resource":[...]}, get first key and return array data k,v = body.first if v.is_a?(Array) || v.is_a?(Hash) v else body end end |
Instance Method Details
#more_pages? ⇒ Boolean
27 28 29 30 |
# File 'lib/hudu/pagination.rb', line 27 def more_pages? # while full page we have next page @page_total == @page_size end |
#next_page!(body) ⇒ Object
21 22 23 24 25 |
# File 'lib/hudu/pagination.rb', line 21 def next_page!(body) @page += 1 a = PagingInfoPager.data(body) @page_total = a.is_a?(Array) ? a.count : 1 end |
#page_options ⇒ Object
17 18 19 |
# File 'lib/hudu/pagination.rb', line 17 def { page: @page } end |