Sha256: a01ef9845aded88b1987042fc233a56ac642a3ad4498f0a21e10860e703d3be2

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

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

module TimeBoss
  class Calendar
    class Week < Support::Unit
      attr_reader :year_index, :index

      def initialize(calendar, year_index, index, start_date, end_date)
        super(calendar, start_date, end_date)
        @year_index = year_index
        @index = index
      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 previous
        if index == 1
          (calendar.year_for(start_date) - 1).weeks.last
        else
          self.class.new(calendar, year_index, index - 1, start_date - 1.week, end_date - 1.week)
        end
      end

      def next
        weeks = calendar.year_for(start_date).weeks
        if index == weeks.last.index
          self.class.new(calendar, year_index + 1, 1, start_date + 1.week, end_date + 1.week)
        else
          weeks[index]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
timeboss-0.0.8 lib/timeboss/calendar/week.rb
timeboss-0.0.7 lib/timeboss/calendar/week.rb
timeboss-0.0.6 lib/timeboss/calendar/week.rb
timeboss-0.0.5 lib/timeboss/calendar/week.rb