Class: Sunspot::Search::CursorPaginatedCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/sunspot/search/cursor_paginated_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, per_page, total, current_cursor, next_page_cursor) ⇒ CursorPaginatedCollection

Returns a new instance of CursorPaginatedCollection.



9
10
11
12
13
14
15
16
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 9

def initialize(collection, per_page, total, current_cursor, next_page_cursor)
  @per_page         = per_page
  @total_count      = total
  @current_cursor   = current_cursor
  @next_page_cursor = next_page_cursor

  replace collection
end

Instance Attribute Details

#current_cursorObject (readonly)

Returns the value of attribute current_cursor.



5
6
7
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 5

def current_cursor
  @current_cursor
end

#next_page_cursorObject (readonly)

Returns the value of attribute next_page_cursor.



5
6
7
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 5

def next_page_cursor
  @next_page_cursor
end

#per_pageObject (readonly) Also known as: limit_value

Returns the value of attribute per_page.



5
6
7
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 5

def per_page
  @per_page
end

#total_countObject (readonly) Also known as: total_entries

Returns the value of attribute total_count.



5
6
7
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 5

def total_count
  @total_count
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 23

def first_page?
  current_cursor == '*'
end

#last_page?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 27

def last_page?
  count < per_page
end

#total_pagesObject Also known as: num_pages



18
19
20
# File 'lib/sunspot/search/cursor_paginated_collection.rb', line 18

def total_pages
  (total_count.to_f / per_page).ceil
end