Sha256: 41594345f56811a7d3811b8b54ffe98759e86e8634e0ba7ec31c58b1ad4f7302

Contents?: true

Size: 566 Bytes

Versions: 3

Compression:

Stored size: 566 Bytes

Contents

module SimpleCalendar
  class WeekCalendar < SimpleCalendar::Calendar
    def week_number
      format = (Date.beginning_of_week == :sunday) ? "%U" : "%W"
      start_date.beginning_of_week.strftime(format).to_i
    end

    def number_of_weeks
      options.fetch(:number_of_weeks, 1)
    end

    def end_week
      week_number + number_of_weeks - 1
    end

    private

      def date_range
        starting = start_date.beginning_of_week
        ending = (starting + (number_of_weeks - 1).weeks).end_of_week

        (starting..ending).to_a
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simple_calendar-2.2.7 lib/simple_calendar/week_calendar.rb
simple_calendar-2.2.6 lib/simple_calendar/week_calendar.rb
simple_calendar-2.2.5 lib/simple_calendar/week_calendar.rb