Module: TimeBoss::Calendar::Support::Navigable

Included in:
Unit
Defined in:
lib/timeboss/calendar/support/navigable.rb

Instance Method Summary collapse

Instance Method Details

#ago(quantity) ⇒ Unit

Fetch the unit some number of units prior to this unit.



34
35
36
# File 'lib/timeboss/calendar/support/navigable.rb', line 34

def ago(quantity)
  previous(quantity + 1).first
end

#ahead(quantity) ⇒ Unit

Fetch the unit some number of units after this unit.



41
42
43
# File 'lib/timeboss/calendar/support/navigable.rb', line 41

def ahead(quantity)
  self.next(quantity + 1).last
end

#nextUnit #next(value) ⇒ Array<Unit>

Overloads:

  • #nextUnit

    Fetch the next unit relative to this unit.

  • #next(value) ⇒ Array<Unit>

    Fetch some next number of units relative to this unit



26
27
28
29
# File 'lib/timeboss/calendar/support/navigable.rb', line 26

def next(quantity = nil)
  return up if quantity.nil?
  gather(:next, quantity)
end

#previousUnit #previous(value) ⇒ Array<Unit>

Overloads:

  • #previousUnit

    Fetch the previous unit relative to this unit.

  • #previous(value) ⇒ Array<Unit>

    Fetch some previous number of units relative to this unit



14
15
16
17
# 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) ⇒ Array<Unit>

Fetch a list of units from this unit until some date.



48
49
50
51
52
53
54
55
56
# 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