Class: TimeBoss::Calendar::Period

Inherits:
Object
  • Object
show all
Includes:
Support::Clampable
Defined in:
lib/timeboss/calendar/period.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Clampable

#clamp

Instance Attribute Details

#beginObject (readonly)

Returns the value of attribute begin.



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

def begin
  @begin
end

#endObject (readonly)

Returns the value of attribute end.



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

def end
  @end
end

Instance Method Details

#current?Boolean

Does this period cover the current date?



113
114
115
# File 'lib/timeboss/calendar/period.rb', line 113

def current?
  to_range.include?(Date.today)
end

#day(index = nil) ⇒ Array<Calendar::Day>?

Get the day this period represents. Returns nil if no single day can be identified.



# File 'lib/timeboss/calendar/period.rb', line 51


#daysArray<Calendar::Day>

Get a list of days that fall within this period.



# File 'lib/timeboss/calendar/period.rb', line 47


#end_dateDate

Get the end date of this period.



19
# File 'lib/timeboss/calendar/period.rb', line 19

delegate :end_date, to: :end

#half(index = nil) ⇒ Array<Calendar::Half>?

Get the half this period represents. Returns nil if no single half can be identified.



# File 'lib/timeboss/calendar/period.rb', line 95


#halvesArray<Calendar::Half>

Get a list of halves that fall within this period.



# File 'lib/timeboss/calendar/period.rb', line 91


#inspectObject



139
140
141
# File 'lib/timeboss/calendar/period.rb', line 139

def inspect
  "#<#{self.class.name}[#{self.begin.inspect}..#{self.end.inspect}] start_date=#{start_date}, end_date=#{end_date}>"
end

#month(index = nil) ⇒ Array<Calendar::Month>?

Get the month this period represents. Returns nil if no single month can be identified.



# File 'lib/timeboss/calendar/period.rb', line 73


#monthsArray<Calendar::Month>

Get a list of months that fall within this period.



# File 'lib/timeboss/calendar/period.rb', line 69


#nameString

Get a simple representation of this period.



# File 'lib/timeboss/calendar/period.rb', line 21


#quarter(index = nil) ⇒ Array<Calendar::Quarter>?

Get the quarter this period represents. Returns nil if no single quarter can be identified.



# File 'lib/timeboss/calendar/period.rb', line 84


#quartersArray<Calendar::Quarter>

Get a list of quarters that fall within this period.



# File 'lib/timeboss/calendar/period.rb', line 80


#start_dateDate

Get the start date of this period.



14
# File 'lib/timeboss/calendar/period.rb', line 14

delegate :start_date, to: :begin

#titleString

Get a “pretty” representation of this period.



# File 'lib/timeboss/calendar/period.rb', line 25


#to_rangeRange<Date, Date>

Express this period as a date range.



135
136
137
# File 'lib/timeboss/calendar/period.rb', line 135

def to_range
  @_to_range ||= start_date..end_date
end

#to_sString

Get a stringified representation of this period.



33
34
35
36
37
38
39
# File 'lib/timeboss/calendar/period.rb', line 33

i[name title to_s].each do |message|
  define_method(message) do
    text = self.begin.public_send(message)
    text = "#{text} #{Parser::RANGE_DELIMITER} #{self.end.public_send(message)}" unless self.end == self.begin
    text
  end
end

#week(index = nil) ⇒ Array<Calendar::Week>?

Get the week this period represents. Returns nil if no single week can be identified.



# File 'lib/timeboss/calendar/period.rb', line 62


#weeksArray<Calendar::Week>

Get a list of weeks that fall within this period.



# File 'lib/timeboss/calendar/period.rb', line 58


#year(index = nil) ⇒ Array<Calendar::Year>?

Get the year this period represents. Returns nil if no single year can be identified.



# File 'lib/timeboss/calendar/period.rb', line 106


#yearsArray<Calendar::Year>

Get a list of years that fall within this period.



# File 'lib/timeboss/calendar/period.rb', line 102