Class: Pagy::Calendar::Week

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

Overview

Calendar week 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 collapse

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 Attribute Details

#week_offsetObject (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_varsObject

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