Class: TimeBoss::Calendar::Period

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#beginObject (readonly)

Returns the value of attribute begin.



6
7
8
# File 'lib/timeboss/calendar/period.rb', line 6

def begin
  @begin
end

#endObject (readonly)

Returns the value of attribute end.



6
7
8
# File 'lib/timeboss/calendar/period.rb', line 6

def end
  @end
end

Instance Method Details

#current?Boolean

Does this period cover the current date?

Returns:

  • (Boolean)


110
111
112
# File 'lib/timeboss/calendar/period.rb', line 110

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.

Returns:



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


#daysArray<Calendar::Day>

Get a list of days that fall within this period.

Returns:



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


#end_dateDate

Get the end date of this period.

Returns:

  • (Date)


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

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.

Returns:



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


#halvesArray<Calendar::Half>

Get a list of halves that fall within this period.

Returns:



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


#inspectObject



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

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.

Returns:



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


#monthsArray<Calendar::Month>

Get a list of months that fall within this period.

Returns:



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


#nameString

Get a simple representation of this period.

Returns:

  • (String)


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


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

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

Returns:



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


#quartersArray<Calendar::Quarter>

Get a list of quarters that fall within this period.

Returns:



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


#start_dateDate

Get the start date of this period.

Returns:

  • (Date)


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

delegate :start_date, to: :begin

#titleString

Get a “pretty” representation of this period.

Returns:

  • (String)


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


#to_rangeRange<Date, Date>

Express this period as a date range.

Returns:

  • (Range<Date, Date>)


132
133
134
# File 'lib/timeboss/calendar/period.rb', line 132

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

#to_sString

Get a stringified representation of this period.

Returns:

  • (String)


30
31
32
33
34
35
36
# File 'lib/timeboss/calendar/period.rb', line 30

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.

Returns:



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


#weeksArray<Calendar::Week>

Get a list of weeks that fall within this period.

Returns:



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


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

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

Returns:



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


#yearsArray<Calendar::Year>

Get a list of years that fall within this period.

Returns:



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