Class: TimeBoss::Calendar::Week

Inherits:
Support::Unit show all
Defined in:
lib/timeboss/calendar/week.rb

Direct Known Subclasses

Support::HasIsoWeeks::Week

Constant Summary

Constants inherited from Support::Unit

Support::Unit::UnsupportedUnitError

Constants included from Support::Translatable

Support::Translatable::PERIODS

Instance Attribute Summary

Attributes inherited from Support::Unit

#calendar, #end_date, #start_date

Instance Method Summary collapse

Methods inherited from Support::Unit

#+, #-, #==, #current?, #dates, #format, #inspect, #offset, #thru, #to_range, type

Methods included from Support::Clampable

#clamp

Methods included from Support::Shiftable

#days_ago, #days_ahead, #halves_ago, #halves_ahead, #in_day, #in_half, #in_month, #in_quarter, #in_week, #in_year, #last_day, #last_half, #last_month, #last_quarter, #last_week, #last_year, #months_ago, #months_ahead, #next_day, #next_half, #next_month, #next_quarter, #next_week, #next_year, #quarters_ago, #quarters_ahead, #this_day, #this_half, #this_month, #this_quarter, #this_week, #this_year, #weeks_ago, #weeks_ahead, #years_ago, #years_ahead

Methods included from Support::Translatable

#day, #days, #half, #halves, #month, #months, #quarter, #quarters, #week, #weeks, #year, #years

Methods included from Support::Navigable

#ago, #ahead, #next, #previous, #until

Constructor Details

#initialize(calendar, start_date, end_date) ⇒ Week

Returns a new instance of Week.



8
9
10
11
# File 'lib/timeboss/calendar/week.rb', line 8

def initialize(calendar, start_date, end_date)
  raise UnsupportedUnitError unless calendar.supports_weeks?
  super(calendar, start_date, end_date)
end

Instance Method Details

#indexInteger

Get the index of this week within its containing year.

Returns:

  • (Integer)


33
34
35
# File 'lib/timeboss/calendar/week.rb', line 33

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

#nameString

Get a simple representation of this week.

Returns:

  • (String)

    (e.g. “2020W32”)



15
16
17
# File 'lib/timeboss/calendar/week.rb', line 15

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

#titleString

Get a “pretty” representation of this week.

Returns:

  • (String)

    (e.g. “Week of August 3, 2020”)



21
22
23
# File 'lib/timeboss/calendar/week.rb', line 21

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

#to_sString

Get a stringified representation of this week.

Returns:

  • (String)

    (e.g. “2020W32: 2020-08-03 thru 2020-08-09”)



27
28
29
# File 'lib/timeboss/calendar/week.rb', line 27

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

#year_indexInteger

Get the year number for this week.

Returns:

  • (Integer)

    (e.g. 2020)



39
40
41
# File 'lib/timeboss/calendar/week.rb', line 39

def year_index
  @_year_index ||= year.year_index
end