Sha256: 0a6c292ef4f02f74768e0ec4968602824039b6acef6ff4f19bdc81e936cc24b8

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

# frozen_string_literal: true
require_relative './support/unit'

module TimeBoss
  class Calendar
    class Week < Support::Unit
      def initialize(calendar, start_date, end_date)
        super(calendar, start_date, end_date)
      end

      def name
        "#{year_index}W#{index}"
      end

      def title
        "Week of #{start_date.strftime('%B %-d, %Y')}"
      end

      def to_s
        "#{name}: #{start_date} thru #{end_date}"
      end

      def index
        @_index ||= (((start_date - year.start_date) + 1) / 7.0).to_i + 1
      end

      def year_index
        @_year_index ||= year.year_index
      end

      private

      def down
        self.class.new(calendar, start_date - 1.week, end_date - 1.week)
      end

      def up
        self.class.new(calendar, start_date + 1.week, end_date + 1.week)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timeboss-0.0.10 lib/timeboss/calendar/week.rb