Sha256: bf18f98d8d815f2e909422d04829e6f83497c60c62bacfd3baa554dd789a17de

Contents?: true

Size: 1.03 KB

Versions: 28

Compression:

Stored size: 1.03 KB

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 week subclass
    class Week < Calendar
      DEFAULT  = { order:  :asc,      # rubocop:disable Style/MutableConstant
                   format: '%Y-%W' }

      protected

      # Setup the calendar variables
      def setup_unit_vars
        super
        @initial = @starting.beginning_of_week
        @final   = @ending.next_week.beginning_of_week
        @pages   = @last = page_offset(@initial, @final)
        @from    = starting_time_for(@page)
        @to      = @from.next_week
      end

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

      def page_offset_at(time)
        page_offset(@initial, time.beginning_of_week)
      end

      private

      def page_offset(time_a, time_b)  # remove in 6.0
        (time_b.time - time_a.time).to_i / 1.week
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
pagy-8.0.2 lib/pagy/calendar/week.rb
pagy-8.0.1 gem/lib/pagy/calendar/week.rb
pagy-8.0.0 lib/pagy/calendar/week.rb
pagy-7.0.11 lib/pagy/calendar/week.rb
pagy-7.0.10 lib/pagy/calendar/week.rb
pagy-7.0.9 lib/pagy/calendar/week.rb
pagy-7.0.8 lib/pagy/calendar/week.rb
pagy-7.0.7 lib/pagy/calendar/week.rb
pagy-7.0.6 lib/pagy/calendar/week.rb
pagy-7.0.5 lib/pagy/calendar/week.rb
pagy-7.0.4 lib/pagy/calendar/week.rb
pagy-7.0.3 lib/pagy/calendar/week.rb
pagy-7.0.2 lib/pagy/calendar/week.rb
pagy-7.0.1 lib/pagy/calendar/week.rb
pagy-6.5.0 lib/pagy/calendar/week.rb
pagy-7.0.0 lib/pagy/calendar/week.rb
pagy-6.4.4 lib/pagy/calendar/week.rb
pagy-6.4.3 lib/pagy/calendar/week.rb
pagy-6.4.2 lib/pagy/calendar/week.rb
pagy-6.4.1 lib/pagy/calendar/week.rb