Class: Pagy::Calendar::Year

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

Overview

Calendar year 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)



96
97
98
99
# File 'lib/pagy/calendar.rb', line 96

def label_for(page, **opts)
  opts[:format] ||= @vars[:year_format]
  localize(new_time(@initial.year + snap(page.to_i)), **opts)
end

#setup_unit_varsObject

Setup the calendar vars when the unit is :year



86
87
88
89
90
91
92
93
# File 'lib/pagy/calendar.rb', line 86

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