Class: TrackerApi::Client::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ Pagination

Returns a new instance of Pagination.



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/tracker_api/client.rb', line 203

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

#headersObject

Returns the value of attribute headers.



201
202
203
# File 'lib/tracker_api/client.rb', line 201

def headers
  @headers
end

#limitObject

Returns the value of attribute limit.



201
202
203
# File 'lib/tracker_api/client.rb', line 201

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



201
202
203
# File 'lib/tracker_api/client.rb', line 201

def offset
  @offset
end

#returnedObject

Returns the value of attribute returned.



201
202
203
# File 'lib/tracker_api/client.rb', line 201

def returned
  @returned
end

#totalObject

Returns the value of attribute total.



201
202
203
# File 'lib/tracker_api/client.rb', line 201

def total
  @total
end

Instance Method Details

#more?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/tracker_api/client.rb', line 221

def more?
  (offset + limit) < total
end

#next_offsetObject



225
226
227
# File 'lib/tracker_api/client.rb', line 225

def next_offset
  offset + limit
end

#next_page_paramsObject



229
230
231
# File 'lib/tracker_api/client.rb', line 229

def next_page_params
  { limit: limit, offset: next_offset }
end