Sha256: f739092cbbdb2ae6423a357f16577242d64ec122e13cbae56a104122aabb0088

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

module Sunspot
  module Search

    class PaginatedCollection < Array

      attr_reader :current_page, :per_page
      attr_accessor :total_count
      alias :total_entries :total_count
      alias :total_entries= :total_count=
      alias :limit_value :per_page

      def initialize(collection, page, per_page, total)
        @current_page = page
        @per_page     = per_page
        @total_count  = total
        replace collection
      end

      def total_pages
        (total_count.to_f / per_page).ceil
      end
      alias :num_pages :total_pages

      def first_page?
        current_page == 1
      end

      def last_page?
        current_page >= total_pages
      end

      def previous_page
        current_page > 1 ? (current_page - 1) : nil
      end
      alias :prev_page :previous_page

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

      def out_of_bounds?
        current_page > total_pages
      end

      def offset
        (current_page - 1) * per_page
      end
      alias :offset_value :offset

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/search/paginated_collection.rb
sunspot-2.7.0 lib/sunspot/search/paginated_collection.rb
sunspot-2.6.0 lib/sunspot/search/paginated_collection.rb
sunspot-2.5.0 lib/sunspot/search/paginated_collection.rb
sunspot-2.4.0 lib/sunspot/search/paginated_collection.rb
sunspot-2.3.0 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.8 lib/sunspot/search/paginated_collection.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/search/paginated_collection.rb
sunspot-2.2.7 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.6 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.5 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.4 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.3 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.2 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.1 lib/sunspot/search/paginated_collection.rb
sunspot-2.2.0 lib/sunspot/search/paginated_collection.rb