Class: Pagy::Calendar
- Defined in:
- lib/pagy/calendar.rb
Overview
Base class for time units subclasses (Year, Month, Week, Day)
Defined Under Namespace
Classes: Day, Month, Week, Year
Constant Summary collapse
- DAY =
60 * 60 * 24
- WEEK =
DAY * 7
Constants inherited from Pagy
DEFAULT, ElasticsearchRails, LABEL_PLACEHOLDER, Meilisearch, PAGE_PLACEHOLDER, Searchkick, VERSION
Instance Attribute Summary collapse
-
#time_order ⇒ Object
readonly
Returns the value of attribute time_order.
-
#utc_from ⇒ Object
readonly
Returns the value of attribute utc_from.
-
#utc_to ⇒ Object
readonly
Returns the value of attribute utc_to.
Attributes inherited from Pagy
#count, #from, #in, #items, #last, #next, #offset, #page, #pages, #params, #prev, #to, #vars
Class Method Summary collapse
-
.create(unit, vars) ⇒ Object
Create a subclass instance.
Instance Method Summary collapse
-
#current_unit_minmax ⇒ Object
Return the minmax of the current page/unit (used by the extra for the next level minmax).
-
#initialize(vars) ⇒ Calendar
constructor
Merge and validate the options, do some simple arithmetic and set a few instance variables.
-
#label(**opts) ⇒ Object
The label for the current page (it can pass along the I18n gem opts when it’s used with the i18n extra).
Methods included from OverflowExtra::Pagy
Methods included from FrontendHelpers::Calendar
Methods inherited from Pagy
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
#initialize(vars) ⇒ Calendar
Merge and validate the options, do some simple arithmetic and set a few instance variables
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pagy/calendar.rb', line 30 def initialize(vars) # rubocop:disable Lint/MissingSuper raise InternalError, 'Pagy::Calendar is a base class; use one of its subclasses.' if instance_of?(Pagy::Calendar) normalize_vars(vars) setup_vars(page: 1) setup_unit_vars setup_params_var raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last @prev = (@page - 1 unless @page == 1) @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1 end |
Instance Attribute Details
#time_order ⇒ Object (readonly)
Returns the value of attribute time_order.
20 21 22 |
# File 'lib/pagy/calendar.rb', line 20 def time_order @time_order end |
#utc_from ⇒ Object (readonly)
Returns the value of attribute utc_from.
20 21 22 |
# File 'lib/pagy/calendar.rb', line 20 def utc_from @utc_from end |
#utc_to ⇒ Object (readonly)
Returns the value of attribute utc_to.
20 21 22 |
# File 'lib/pagy/calendar.rb', line 20 def utc_to @utc_to end |
Class Method Details
.create(unit, vars) ⇒ Object
Create a subclass instance
23 24 25 26 27 |
# File 'lib/pagy/calendar.rb', line 23 def self.create(unit, vars) raise InternalError, "unit must be in #{UNITS.keys.inspect}; got #{unit}" unless UNITS.key?(unit) UNITS[unit].new(vars) end |
Instance Method Details
#current_unit_minmax ⇒ Object
Return the minmax of the current page/unit (used by the extra for the next level minmax)
49 50 51 |
# File 'lib/pagy/calendar.rb', line 49 def current_unit_minmax [@utc_from.getlocal(@utc_offset), @utc_to.getlocal(@utc_offset)] end |
#label(**opts) ⇒ Object
The label for the current page (it can pass along the I18n gem opts when it’s used with the i18n extra)
44 45 46 |
# File 'lib/pagy/calendar.rb', line 44 def label(**opts) label_for(@page, **opts) end |