Class: Pagy::Offset
- Includes:
- Deprecated::Offset, NumericHelpers, Rangeable, Shiftable
- Defined in:
- lib/pagy/classes/offset/offset.rb,
lib/pagy/classes/offset/countish.rb,
lib/pagy/classes/offset/countless.rb
Overview
Implements Offset Pagination
Direct Known Subclasses
Defined Under Namespace
Constant Summary collapse
- DEFAULT =
{ page: 1 }.freeze
Constants inherited from Pagy
A_TAG, DEFAULT_DATA_KEYS, DEFAULT_HEADERS_MAP, LABEL_TOKEN, LIMIT_TOKEN, Method, OPTIONS, PAGE_TOKEN, ROOT, SERIES_SLOTS, VERSION
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#last ⇒ Object
(also: #pages)
readonly
Returns the value of attribute last.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Attributes inherited from Pagy
Instance Method Summary collapse
-
#initialize ⇒ Offset
constructor
A new instance of Offset.
- #records(collection) ⇒ Object
Methods included from NumericHelpers
#info_tag, #input_nav_js, #limit_tag_js, #previous_tag, #series_nav, #series_nav_js
Methods included from Rangeable
Methods inherited from Pagy
#data_hash, #headers_hash, #next_tag, #page_url, #urls_hash
Methods included from Configurable
#dev_tools, #options, #sync, #sync_javascript, #translate_with_the_slower_i18n_gem!
Methods included from Discontinued
Methods included from Deprecated::Pagy
Constructor Details
#initialize ⇒ Offset
Returns a new instance of Offset.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pagy/classes/offset/offset.rb', line 18 def initialize(**) (**) assign_and_check(limit: 1, count: 0, page: 1) assign_last assign_offset unless in_range? { @page <= @last } assign_empty_page_variables return end @from = [@offset + 1, @count].min @to = [@offset + @limit, @count].min @in = [@to - @from + 1, @count].min assign_previous_and_next end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def count @count end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def from @from end |
#in ⇒ Object (readonly)
Returns the value of attribute in.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def in @in end |
#last ⇒ Object (readonly) Also known as: pages
Returns the value of attribute last.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def last @last end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def next @next end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def offset @offset end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def previous @previous end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
36 37 38 |
# File 'lib/pagy/classes/offset/offset.rb', line 36 def to @to end |
Instance Method Details
#records(collection) ⇒ Object
39 40 41 |
# File 'lib/pagy/classes/offset/offset.rb', line 39 def records(collection) collection.offset(@offset).limit(@limit) end |