Class: CronTab::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/cron_tab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, e) ⇒ Field

Returns a new instance of Field


118
119
120
121
# File 'lib/cron_tab.rb', line 118

def initialize(r, e)
  self.range = r
  self.every = e
end

Instance Attribute Details

#everyObject

Returns the value of attribute every


116
117
118
# File 'lib/cron_tab.rb', line 116

def every
  @every
end

#rangeObject

Returns the value of attribute range


116
117
118
# File 'lib/cron_tab.rb', line 116

def range
  @range
end

Instance Method Details

#===(rhs) ⇒ Object


123
124
125
126
127
# File 'lib/cron_tab.rb', line 123

def ===(rhs)
  b = true
  b = b && ( (rhs - range.first) % every == 0 )
  b = b && ( range === rhs )
end

#nextof(now) ⇒ Object


129
130
131
132
133
134
135
136
137
# File 'lib/cron_tab.rb', line 129

def nextof(now)
  if now < range.first then
    nextof(range.first)
  elsif range.last < now || (range.exclude_end? && range.last <= now) then
    nil
  else
    now + ( (now - range.first) % every )
  end
end