Class: Veeam::RequestPagination::PagingInfoPager
- Inherits:
-
Object
- Object
- Veeam::RequestPagination::PagingInfoPager
- Defined in:
- lib/veeam/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!(data) ⇒ Object
- #page_info(body) ⇒ Object
- #page_options ⇒ Object
Constructor Details
#initialize(page_size) ⇒ PagingInfoPager
Returns a new instance of PagingInfoPager.
11 12 13 14 15 16 |
# File 'lib/veeam/pagination.rb', line 11 def initialize(page_size) @offset = 0 @limit = page_size # we halways have a first page @total = @offset + 1 end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
10 11 12 |
# File 'lib/veeam/pagination.rb', line 10 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
10 11 12 |
# File 'lib/veeam/pagination.rb', line 10 def offset @offset end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
10 11 12 |
# File 'lib/veeam/pagination.rb', line 10 def total @total end |
Class Method Details
.data(body) ⇒ Object
36 37 38 |
# File 'lib/veeam/pagination.rb', line 36 def self.data(body) body['data'] ? body['data'] : body end |
Instance Method Details
#more_pages? ⇒ Boolean
28 29 30 |
# File 'lib/veeam/pagination.rb', line 28 def more_pages? @offset < @total end |
#next_page!(data) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/veeam/pagination.rb', line 20 def next_page!(data) @offset += @limit = page_info(data) if @total = ['total'].to_i end end |
#page_info(body) ⇒ Object
32 33 34 |
# File 'lib/veeam/pagination.rb', line 32 def page_info(body) body['meta']['pagingInfo'] if body['meta'] && body['meta']['pagingInfo'] end |
#page_options ⇒ Object
17 18 19 |
# File 'lib/veeam/pagination.rb', line 17 def { limit: @limit, offset: @offset } end |