Class: Pagy::Calendar::Month

Inherits:
Pagy::Calendar show all
Defined in:
lib/pagy/calendar.rb

Overview

Calendar month subclass

Constant Summary

Constants inherited from Pagy::Calendar

DAY, WEEK

Constants inherited from Pagy

DEFAULT, ElasticsearchRails, LABEL_PLACEHOLDER, Meilisearch, PAGE_PLACEHOLDER, Searchkick, VERSION

Instance Attribute Summary

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

Methods inherited from Pagy::Calendar

create, #current_unit_minmax, #initialize, #label

Methods included from I18nExtra::Calendar

#localize

Methods included from OverflowExtra::Pagy

#initialize, #overflow?

Methods included from FrontendHelpers::Calendar

#label_sequels

Methods inherited from Pagy

#initialize, #label, root, #series

Methods included from SearchkickExtra::Pagy

#new_from_searchkick

Methods included from MeilisearchExtra::Pagy

#new_from_meilisearch

Methods included from ElasticsearchRailsExtra::Pagy

#new_from_elasticsearch_rails

Methods included from GearboxExtra

#setup_items_var, #setup_pages_var

Methods included from FrontendHelpers::Pagy

#label_sequels, #sequels

Constructor Details

This class inherits a constructor from Pagy::Calendar

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)



115
116
117
118
# File 'lib/pagy/calendar.rb', line 115

def label_for(page, **opts)
  opts[:format] ||= @vars[:month_format]
  localize(bump_month(@initial, snap(page.to_i)), **opts)
end

#setup_unit_varsObject

Setup the calendar vars when the unit is :month



105
106
107
108
109
110
111
112
# File 'lib/pagy/calendar.rb', line 105

def setup_unit_vars
  min, max  = super(:month_format)
  @initial  = new_time(min.year, min.month)
  @final    = bump_month(max)
  @pages    = @last = months(@final) - months(@initial)
  @utc_from = bump_month(@initial, snap).utc
  @utc_to   = bump_month(@initial, snap + 1).utc
end