Class: Search::Pagination
- Inherits:
-
Object
- Object
- Search::Pagination
- 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
999
Instance Attribute Summary collapse
-
#next_offset ⇒ Object
readonly
Returns the value of attribute next_offset.
-
#total ⇒ Integer
readonly
The current value of total.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
-
#initialize(raw_body) ⇒ Pagination
constructor
A new instance of Pagination.
-
#object ⇒ Hash
Pagination_object a Hash including pagination details.
Constructor Details
#initialize(raw_body) ⇒ Pagination
Returns a new instance of Pagination.
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_offset ⇒ Object (readonly)
Returns the value of attribute next_offset.
26 27 28 |
# File 'lib/search/pagination.rb', line 26 def next_offset @next_offset end |
#total ⇒ Integer (readonly)
Returns the current value of total.
9 10 11 |
# File 'lib/search/pagination.rb', line 9 def total @total end |
#total_entries ⇒ Object (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_pages ⇒ Object (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
#object ⇒ Hash
Returns pagination_object a Hash including pagination details.
38 39 40 |
# File 'lib/search/pagination.rb', line 38 def object pagination_object end |