Class: Pagy::Calendar::Unit

Inherits:
Pagy
  • Object
show all
Includes:
Rangeable, Shiftable
Defined in:
lib/pagy/classes/calendar/unit.rb

Overview

Base class for time units subclasses (Year, Quarter, Month, Week, Day)

To define a “bimester” unit you should:

  • Define a ‘Pagy::Calendar::Bimester` class

  • Add the ‘:bimester` unit symbol in the `Pagy::Calendar::UNITS`

  • Ensure the desc durtion order of the UNITS (i.e. insert it between ‘:quarter` and `:month`)

Direct Known Subclasses

Day, Month, Quarter, Week, Year

Constant Summary collapse

DEFAULT =
{ page: 1 }.freeze

Constants inherited from Pagy

A_TAG, DEFAULT_DATA_KEYS, DEFAULT_HEADERS_MAP, LABEL_TOKEN, LIMIT_TOKEN, Method, PAGE_TOKEN, ROOT, SERIES_SLOTS, VERSION

Instance Attribute Summary collapse

Attributes inherited from Pagy

#in, #limit, #next, #options, #page

Instance Method Summary collapse

Methods included from Rangeable

#in_range?

Methods inherited from Pagy

#data_hash, #headers_hash, #info_tag, #input_nav_js, #limit_tag_js, #next_tag, options, #page_url, #previous_tag, #series_nav, #series_nav_js, #urls_hash

Methods included from Pagy::Configurable

#dev_tools, #sync_javascript, #translate_with_the_slower_i18n_gem!

Constructor Details

#initializeUnit

Returns a new instance of Unit.



20
21
22
23
24
25
26
27
# File 'lib/pagy/classes/calendar/unit.rb', line 20

def initialize(**)
  assign_options(**)
  assign_and_check(page: 1)
  assign_unit_variables
  return unless in_range? { @page <= @last }

  assign_previous_and_next
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



29
30
31
# File 'lib/pagy/classes/calendar/unit.rb', line 29

def from
  @from
end

#lastObject (readonly) Also known as: pages

Returns the value of attribute last.



29
30
31
# File 'lib/pagy/classes/calendar/unit.rb', line 29

def last
  @last
end

#orderObject (readonly)

Returns the value of attribute order.



29
30
31
# File 'lib/pagy/classes/calendar/unit.rb', line 29

def order
  @order
end

#previousObject (readonly)

Returns the value of attribute previous.



29
30
31
# File 'lib/pagy/classes/calendar/unit.rb', line 29

def previous
  @previous
end

#toObject (readonly)

Returns the value of attribute to.



29
30
31
# File 'lib/pagy/classes/calendar/unit.rb', line 29

def to
  @to
end