Class: Azeroth::RequestHandler::Pagination Private

Inherits:
Object
  • Object
show all
Defined in:
lib/azeroth/request_handler/pagination.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrapper for request finding pagination attributes

Instance Method Summary collapse

Constructor Details

#initialize(params, options) ⇒ Pagination

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Pagination.



9
10
11
12
# File 'lib/azeroth/request_handler/pagination.rb', line 9

def initialize(params, options)
  @params = params
  @options = options
end

Instance Method Details

#current_pageInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

calculates current page

Returns:

  • (Integer)


44
45
46
# File 'lib/azeroth/request_handler/pagination.rb', line 44

def current_page
  (params[:page] || 1).to_i
end

#limitInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

limit used in pagination

limit is retrieved from params[:page]

Returns:

  • (Integer)


35
36
37
# File 'lib/azeroth/request_handler/pagination.rb', line 35

def limit
  (params[:per_page] || per_page).to_i
end

#offsetInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

offest used in pagination

offset is retrieved from params[:per_page] or options.per_page

Returns:

  • (Integer)


24
25
26
# File 'lib/azeroth/request_handler/pagination.rb', line 24

def offset
  (current_page - 1) * limit
end