Sha256: a92b2baceaefe3049c1ec911012e976f6288c344777fff64498b89531420ccea

Contents?: true

Size: 643 Bytes

Versions: 4

Compression:

Stored size: 643 Bytes

Contents

module Indexers
  module Pagination

    def total_pages
      @total_pages ||= [(total_count.to_f / page_length).ceil, 1].max
    end

    def previous_page
      @previous_page ||= (current_page > 1 ? (current_page - 1) : nil)
    end

    def next_page
      @next_page ||= (current_page < total_pages ? (current_page + 1) : nil)
    end

    def first_page
      1
    end

    def last_page
      total_pages
    end

    def out_of_bounds?
      @out_of_bounds ||= (current_page > total_pages || current_page < first_page)
    end

    def total_count
      @total_count ||= (response['hits']['total'].to_i - padding)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
indexers-5.1.1 lib/indexers/pagination.rb
indexers-5.1.0 lib/indexers/pagination.rb
indexers-4.1.0.1 lib/indexers/pagination.rb
indexers-4.1.0.0 lib/indexers/pagination.rb