Class: Pagy::Calendar::Week
- Inherits:
-
Pagy::Calendar
- Object
- Pagy
- Pagy::Calendar
- Pagy::Calendar::Week
- Defined in:
- lib/pagy/calendar.rb
Overview
Calendar week subclass
Constant Summary
Constants inherited from Pagy::Calendar
Constants inherited from Pagy
DEFAULT, ElasticsearchRails, LABEL_PLACEHOLDER, Meilisearch, PAGE_PLACEHOLDER, Searchkick, VERSION
Instance Attribute Summary collapse
-
#week_offset ⇒ Object
readonly
Returns the value of attribute week_offset.
Attributes inherited from Pagy::Calendar
#time_order, #utc_from, #utc_to
Attributes inherited from Pagy
#count, #from, #in, #items, #last, #next, #offset, #page, #pages, #params, #prev, #to, #vars
Instance Method Summary collapse
-
#label_for(page, **opts) ⇒ Object
Generate a label for each page (it can pass along the I18n gem opts when it’s used with the i18n extra).
-
#setup_unit_vars ⇒ Object
Setup the calendar vars when the unit is :week.
Methods inherited from Pagy::Calendar
create, #current_unit_minmax, #initialize, #label
Methods included from I18nExtra::Calendar
Methods included from OverflowExtra::Pagy
Methods included from FrontendHelpers::Calendar
Methods inherited from Pagy
#initialize, #label, root, #series
Methods included from SearchkickExtra::Pagy
Methods included from MeilisearchExtra::Pagy
Methods included from ElasticsearchRailsExtra::Pagy
Methods included from GearboxExtra
#setup_items_var, #setup_pages_var
Methods included from FrontendHelpers::Pagy
Constructor Details
This class inherits a constructor from Pagy::Calendar
Instance Attribute Details
#week_offset ⇒ Object (readonly)
Returns the value of attribute week_offset.
138 139 140 |
# File 'lib/pagy/calendar.rb', line 138 def week_offset @week_offset end |
Instance Method Details
#label_for(page, **opts) ⇒ Object
Generate a label for each page (it can pass along the I18n gem opts when it’s used with the i18n extra)
152 153 154 155 |
# File 'lib/pagy/calendar.rb', line 152 def label_for(page, **opts) opts[:format] ||= @vars[:week_format] localize(@initial + (snap(page.to_i) * WEEK), **opts) end |
#setup_unit_vars ⇒ Object
Setup the calendar vars when the unit is :week
141 142 143 144 145 146 147 148 149 |
# File 'lib/pagy/calendar.rb', line 141 def setup_unit_vars setup_vars(week_offset: 0) min, max = super(:week_format) @initial = week_start(min) @final = week_start(max) + WEEK @pages = @last = (@final - @initial).to_i / WEEK @utc_from = (@initial + (snap * WEEK)).utc @utc_to = @utc_from + WEEK end |