Class: TimeBoss::Calendar::Week
- Inherits:
-
Support::Unit
- Object
- Support::Unit
- TimeBoss::Calendar::Week
- Defined in:
- lib/timeboss/calendar/week.rb
Direct Known Subclasses
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
-
#index ⇒ Integer
Get the index of this week within its containing year.
-
#initialize(calendar, start_date, end_date) ⇒ Week
constructor
A new instance of Week.
-
#name ⇒ String
Get a simple representation of this week.
-
#title ⇒ String
Get a “pretty” representation of this week.
-
#to_s ⇒ String
Get a stringified representation of this week.
-
#year_index ⇒ Integer
Get the year number for this week.
Methods inherited from Support::Unit
#+, #-, #==, #current?, #dates, #format, #inspect, #offset, #thru, #to_range, type
Methods included from Support::Clampable
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
#index ⇒ Integer
Get the index of this week within its containing year.
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 |
#name ⇒ String
Get a simple representation of this week.
15 16 17 |
# File 'lib/timeboss/calendar/week.rb', line 15 def name "#{year_index}W#{index}" end |
#title ⇒ String
Get a “pretty” representation of this week.
21 22 23 |
# File 'lib/timeboss/calendar/week.rb', line 21 def title "Week of #{start_date.strftime("%B %-d, %Y")}" end |
#to_s ⇒ String
Get a stringified representation of this week.
27 28 29 |
# File 'lib/timeboss/calendar/week.rb', line 27 def to_s "#{name}: #{start_date} thru #{end_date}" end |
#year_index ⇒ Integer
Get the year number for this week.
39 40 41 |
# File 'lib/timeboss/calendar/week.rb', line 39 def year_index @_year_index ||= year.year_index end |