class TimeBoss::Calendar::Support::Unit
Constants
- UnsupportedUnitError
Attributes
Public Class Methods
# 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
# File lib/timeboss/calendar/support/unit.rb, line 19 def self.type name.demodulize.underscore end
Public Instance Methods
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
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
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
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 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
# File lib/timeboss/calendar/support/unit.rb, line 87 def inspect "#<#{self.class.name} start_date=#{start_date}, end_date=#{end_date}>" end
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
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
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