class TimeBoss::Calendar::Support::Unit

Constants

UnsupportedUnitError

Attributes

calendar[R]
end_date[R]
start_date[R]

Public Class Methods

new(calendar, start_date, end_date) click to toggle source
# File lib/timeboss/calendar/support/unit.rb, line 23
def initialize(calendar, start_date, end_date)
  @calendar = calendar
  @start_date = start_date
  @end_date = end_date
end
type() click to toggle source
# File lib/timeboss/calendar/support/unit.rb, line 19
def self.type
  name.demodulize.underscore
end

Public Instance Methods

+(other) click to toggle source

Move some number of units forward from this unit. @param value [Integer] @return [Unit]

# File lib/timeboss/calendar/support/unit.rb, line 70
def +(other)
  offset(other)
end
-(other) click to toggle source

Move some number of units backward from this unit. @param value [Integer] @return [Unit]

# File lib/timeboss/calendar/support/unit.rb, line 77
def -(other)
  offset(-other)
end
==(other) click to toggle source

Is the specified unit equal to this one, based on its unit type and date range? @param entry [Unit] the unit to compare @return [Boolean] true when periods are equal

# File lib/timeboss/calendar/support/unit.rb, line 32
def ==(other)
  self.class == other.class && start_date == other.start_date && end_date == other.end_date
end
current?() click to toggle source

Does this period cover the current date? @return [Boolean]

# File lib/timeboss/calendar/support/unit.rb, line 52
def current?
  Date.today.between?(start_date, end_date)
end
format(*periods) click to toggle source

Format this period based on specified granularities. @param periods [Array<Symbol, String>] the periods to include (`half, week`, or `quarter`) @return [String] (e.g. “2020H2W7” or “2020Q3”)

# File lib/timeboss/calendar/support/unit.rb, line 39
def format(*periods)
  Formatter.new(self, periods.presence || Formatter::PERIODS).to_s
end
inspect() click to toggle source
# File lib/timeboss/calendar/support/unit.rb, line 87
def inspect
  "#<#{self.class.name} start_date=#{start_date}, end_date=#{end_date}>"
end
offset(value) click to toggle source

Return the unit relative to this one by the specified offset. Offset values can be positive or negative. @param value [Integer] @return [Unit]

# File lib/timeboss/calendar/support/unit.rb, line 60
def offset(value)
  method = value.negative? ? :previous : :next
  base = self
  value.abs.times { base = base.public_send(method) }
  base
end
thru(unit) click to toggle source

Starting from this unit of time, build a period extending through the specified time unit. @param unit [Unit] the period to extend through @return [Period]

# File lib/timeboss/calendar/support/unit.rb, line 46
def thru(unit)
  Period.new(calendar, self, unit)
end
to_range() click to toggle source

Express this period as a date range. @return [Range<Date, Date>]

# File lib/timeboss/calendar/support/unit.rb, line 83
def to_range
  @_to_range ||= start_date..end_date
end