Sha256: 09428042a1f39c90b99f64a13a10daf35493c3a8757cbf8622efb5c5cb7338ba

Contents?: true

Size: 946 Bytes

Versions: 15

Compression:

Stored size: 946 Bytes

Contents

# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/calendar
# frozen_string_literal: true

class Pagy # :nodoc:
  class Calendar # :nodoc:
    # Calendar year subclass
    class Year < Calendar
      DEFAULT = { size:   10,   # rubocop:disable Style/MutableConstant
                  order:  :asc,
                  format: '%Y' }

      protected

      # Setup the calendar variables
      def setup_unit_vars
        super
        @initial = @starting.beginning_of_year
        @final   = @ending.next_year.beginning_of_year
        @pages   = @last = @final.year - @initial.year
        @from    = starting_time_for(@page)
        @to      = @from.next_year
      end

      # Starting time for the page
      def starting_time_for(page)
        @initial.years_since(time_offset_for(page))
      end

      def page_offset_at(time)
        time.beginning_of_year.year - @initial.year
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pagy-8.0.2 lib/pagy/calendar/year.rb
pagy-8.0.1 gem/lib/pagy/calendar/year.rb
pagy-8.0.0 lib/pagy/calendar/year.rb
pagy-7.0.11 lib/pagy/calendar/year.rb
pagy-7.0.10 lib/pagy/calendar/year.rb
pagy-7.0.9 lib/pagy/calendar/year.rb
pagy-7.0.8 lib/pagy/calendar/year.rb
pagy-7.0.7 lib/pagy/calendar/year.rb
pagy-7.0.6 lib/pagy/calendar/year.rb
pagy-7.0.5 lib/pagy/calendar/year.rb
pagy-7.0.4 lib/pagy/calendar/year.rb
pagy-7.0.3 lib/pagy/calendar/year.rb
pagy-7.0.2 lib/pagy/calendar/year.rb
pagy-7.0.1 lib/pagy/calendar/year.rb
pagy-7.0.0 lib/pagy/calendar/year.rb