Class: TrackerApi::Client::Pagination
- Defined in:
- lib/tracker_api/client.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#returned ⇒ Object
Returns the value of attribute returned.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(headers) ⇒ Pagination
constructor
A new instance of Pagination.
- #more? ⇒ Boolean
- #next_offset ⇒ Object
- #next_page_params ⇒ Object
Constructor Details
#initialize(headers) ⇒ Pagination
Returns a new instance of Pagination.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/tracker_api/client.rb', line 248 def initialize(headers) @headers = headers @total = headers['x-tracker-pagination-total'].to_i @limit = headers['x-tracker-pagination-limit'].to_i @offset = headers['x-tracker-pagination-offset'].to_i @returned = headers['x-tracker-pagination-returned'].to_i # if offset is negative (e.g. Iterations Endpoint). # For the 'Done' scope, negative numbers can be passed, which # specifies the number of iterations preceding the 'Current' iteration. # then need to adjust the negative offset to account for a smaller total, # and set total to zero since we are paginating from -X to 0. if @offset < 0 @offset = -@total if @offset.abs > @total @total = 0 end end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
246 247 248 |
# File 'lib/tracker_api/client.rb', line 246 def headers @headers end |
#limit ⇒ Object
Returns the value of attribute limit.
246 247 248 |
# File 'lib/tracker_api/client.rb', line 246 def limit @limit end |
#offset ⇒ Object
Returns the value of attribute offset.
246 247 248 |
# File 'lib/tracker_api/client.rb', line 246 def offset @offset end |
#returned ⇒ Object
Returns the value of attribute returned.
246 247 248 |
# File 'lib/tracker_api/client.rb', line 246 def returned @returned end |
#total ⇒ Object
Returns the value of attribute total.
246 247 248 |
# File 'lib/tracker_api/client.rb', line 246 def total @total end |
Instance Method Details
#more? ⇒ Boolean
266 267 268 |
# File 'lib/tracker_api/client.rb', line 266 def more? (offset + limit) < total end |
#next_offset ⇒ Object
270 271 272 |
# File 'lib/tracker_api/client.rb', line 270 def next_offset offset + limit end |
#next_page_params ⇒ Object
274 275 276 |
# File 'lib/tracker_api/client.rb', line 274 def next_page_params { limit: limit, offset: next_offset } end |