Class: Search::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/search/pagination.rb

Overview

A Utility class encapsulating logic to calculate pagination offsets from a given results set.

Constant Summary collapse

ENTRIES_PER_PAGE =

Default size for per-request results count is 20 per page, max is 50. Our design choice is to display 10 results per page.

10
OFFSET_LIMIT =

Due to Search.gov’s offset max of 999, we cannot view pages where the offset param exceeds 999. This influences our:

- total_viewable_pages
- total_viewable_entries

See Also:

999

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_body) ⇒ Pagination

Returns a new instance of Pagination.

Parameters:

  • raw_body (Hash)

    a Hash from the ‘web’ object found in the results response



30
31
32
33
34
# File 'lib/search/pagination.rb', line 30

def initialize(raw_body)
  @next_offset = raw_body.dig('web', 'next_offset')
  @total_entries = raw_body.dig('web', 'total')
  @total_pages = (total_entries / ENTRIES_PER_PAGE.to_f).ceil
end

Instance Attribute Details

#next_offsetObject (readonly)

Returns the value of attribute next_offset.



26
27
28
# File 'lib/search/pagination.rb', line 26

def next_offset
  @next_offset
end

#totalInteger (readonly)

Returns the current value of total.

Returns:

  • (Integer)

    the current value of total



9
10
11
# File 'lib/search/pagination.rb', line 9

def total
  @total
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



26
27
28
# File 'lib/search/pagination.rb', line 26

def total_entries
  @total_entries
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



26
27
28
# File 'lib/search/pagination.rb', line 26

def total_pages
  @total_pages
end

Instance Method Details

#objectHash

Returns pagination_object a Hash including pagination details.

Returns:

  • (Hash)

    pagination_object a Hash including pagination details



38
39
40
# File 'lib/search/pagination.rb', line 38

def object
  pagination_object
end