module TimeBoss::Calendar::Support::Navigable

Public Instance Methods

ago(quantity) click to toggle source

Fetch the unit some number of units prior to this unit. @param quantity [Integer] @return [Unit]

# File lib/timeboss/calendar/support/navigable.rb, line 34
def ago(quantity)
  previous(quantity + 1).first
end
ahead(quantity) click to toggle source

Fetch the unit some number of units after this unit. @param quantity [Integer] @return [Unit]

# File lib/timeboss/calendar/support/navigable.rb, line 41
def ahead(quantity)
  self.next(quantity + 1).last
end
next(quantity = nil) click to toggle source

@overload next

Fetch the next unit relative to this unit.
@return [Unit]

@overload next(value)

Fetch some next number of units relative to this unit
@param quantity [Integer]
@return [Array<Unit>]
# File lib/timeboss/calendar/support/navigable.rb, line 26
def next(quantity = nil)
  return up if quantity.nil?
  gather(:next, quantity)
end
previous(quantity = nil) click to toggle source

@overload previous

Fetch the previous unit relative to this unit.
@return [Unit]

@overload previous(value)

Fetch some previous number of units relative to this unit
@param quantity [Integer]
@return [Array<Unit>]
# File lib/timeboss/calendar/support/navigable.rb, line 14
def previous(quantity = nil)
  return down if quantity.nil?
  gather(:previous, quantity).reverse
end
until(end_date) click to toggle source

Fetch a list of units from this unit until some date. @param end_date [Date] @return [Array<Unit>]

# File lib/timeboss/calendar/support/navigable.rb, line 48
def until(end_date)
  entry = self
  [entry].tap do |entries|
    until entry.end_date >= end_date
      entry = entry.next
      entries << entry
    end
  end
end

Private Instance Methods

gather(navigator, quantity) click to toggle source
# File lib/timeboss/calendar/support/navigable.rb, line 60
def gather(navigator, quantity)
  [].tap do |entries|
    entry = self
    while quantity > 0
      entries << entry
      entry = entry.public_send(navigator)
      quantity -= 1
    end
  end
end