Class: Sunspot::Search::PaginatedCollection
- Inherits:
-
Array
- Object
- Array
- Sunspot::Search::PaginatedCollection
- Defined in:
- lib/sunspot/search/paginated_collection.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
(also: #limit_value)
readonly
Returns the value of attribute per_page.
-
#total_count ⇒ Object
(also: #total_entries)
Returns the value of attribute total_count.
Instance Method Summary collapse
- #first_page? ⇒ Boolean
-
#initialize(collection, page, per_page, total) ⇒ PaginatedCollection
constructor
A new instance of PaginatedCollection.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #offset ⇒ Object (also: #offset_value)
- #out_of_bounds? ⇒ Boolean
- #previous_page ⇒ Object
- #total_pages ⇒ Object (also: #num_pages)
Constructor Details
#initialize(collection, page, per_page, total) ⇒ PaginatedCollection
Returns a new instance of PaginatedCollection.
12 13 14 15 16 17 |
# File 'lib/sunspot/search/paginated_collection.rb', line 12 def initialize(collection, page, per_page, total) @current_page = page @per_page = per_page @total_count = total replace collection end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
6 7 8 |
# File 'lib/sunspot/search/paginated_collection.rb', line 6 def current_page @current_page end |
#per_page ⇒ Object (readonly) Also known as: limit_value
Returns the value of attribute per_page.
6 7 8 |
# File 'lib/sunspot/search/paginated_collection.rb', line 6 def per_page @per_page end |
#total_count ⇒ Object Also known as: total_entries
Returns the value of attribute total_count.
7 8 9 |
# File 'lib/sunspot/search/paginated_collection.rb', line 7 def total_count @total_count end |
Instance Method Details
#first_page? ⇒ Boolean
24 25 26 |
# File 'lib/sunspot/search/paginated_collection.rb', line 24 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
28 29 30 |
# File 'lib/sunspot/search/paginated_collection.rb', line 28 def last_page? current_page >= total_pages end |
#next_page ⇒ Object
36 37 38 |
# File 'lib/sunspot/search/paginated_collection.rb', line 36 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#offset ⇒ Object Also known as: offset_value
44 45 46 |
# File 'lib/sunspot/search/paginated_collection.rb', line 44 def offset (current_page - 1) * per_page end |
#out_of_bounds? ⇒ Boolean
40 41 42 |
# File 'lib/sunspot/search/paginated_collection.rb', line 40 def out_of_bounds? current_page > total_pages end |
#previous_page ⇒ Object
32 33 34 |
# File 'lib/sunspot/search/paginated_collection.rb', line 32 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#total_pages ⇒ Object Also known as: num_pages
19 20 21 |
# File 'lib/sunspot/search/paginated_collection.rb', line 19 def total_pages (total_count.to_f / per_page).ceil end |