Class: TimeBoss::Calendar::Support::MonthlyUnit

Inherits:
Unit
  • Object
show all
Defined in:
lib/timeboss/calendar/support/monthly_unit.rb

Direct Known Subclasses

Half, Month, Quarter, Year

Constant Summary

Constants inherited from Unit

Unit::UnsupportedUnitError

Constants included from Translatable

Translatable::PERIODS

Instance Attribute Summary collapse

Attributes inherited from Unit

#calendar, #end_date, #start_date

Instance Method Summary collapse

Methods inherited from Unit

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

Methods included from 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 Translatable

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

Methods included from Navigable

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

Constructor Details

#initialize(calendar, year_index, index, start_date, end_date) ⇒ MonthlyUnit

Returns a new instance of MonthlyUnit.



11
12
13
14
15
# File 'lib/timeboss/calendar/support/monthly_unit.rb', line 11

def initialize(calendar, year_index, index, start_date, end_date)
  super(calendar, start_date, end_date)
  @year_index = year_index
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



9
10
11
# File 'lib/timeboss/calendar/support/monthly_unit.rb', line 9

def index
  @index
end

#year_indexObject (readonly)

Returns the value of attribute year_index.



9
10
11
# File 'lib/timeboss/calendar/support/monthly_unit.rb', line 9

def year_index
  @year_index
end

Instance Method Details

#to_sString

Get a stringified representation of this unit.

Returns:

  • (String)

    (e.g. “2020Q3: 2020-06-29 thru 2020-09-27”)



19
20
21
# File 'lib/timeboss/calendar/support/monthly_unit.rb', line 19

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

#weeksArray<Week>

Get a list of weeks contained within this period.

Returns:

Raises:



25
26
27
28
29
# File 'lib/timeboss/calendar/support/monthly_unit.rb', line 25

def weeks
  raise UnsupportedUnitError unless calendar.supports_weeks?
  base = calendar.year(year_index)
  calendar.weeks_in(year: base).select { |w| (w.dates & dates).count >= 4 }
end