class Quiver::Action::PaginationLinkBuilder

Attributes

limit[RW]
offset[RW]
request_path_with_query[RW]
total_count[RW]

Public Class Methods

new(request_path_with_query, offset, limit, total_count) click to toggle source
# File lib/quiver/action/pagination_link_builder.rb, line 4
def initialize(request_path_with_query, offset, limit, total_count)
  self.request_path_with_query = request_path_with_query
  self.offset = offset
  self.limit = limit
  self.total_count = total_count
end

Public Instance Methods

Private Instance Methods

last_page() click to toggle source
# File lib/quiver/action/pagination_link_builder.rb, line 56
def last_page
  if limit == -1
    0
  else
    # rounds total_count down to the offset that
    # represents the last page of the resources
    (total_count / limit) * limit
  end
end
next_page() click to toggle source
# File lib/quiver/action/pagination_link_builder.rb, line 40
def next_page
  if limit != -1 && total_count > offset + limit
    offset + limit
  end
end
parsed_uri() click to toggle source
# File lib/quiver/action/pagination_link_builder.rb, line 36
def parsed_uri
  URI.parse(request_path_with_query)
end
previous_page() click to toggle source
# File lib/quiver/action/pagination_link_builder.rb, line 46
def previous_page
  if offset > 0
    if limit == -1
      0
    else
      [offset - limit, 0].max
    end
  end
end