Class: CronFormat

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cron_string, now = Time.now, debug: false) ⇒ CronFormat

Returns a new instance of CronFormat.



20
21
22
23
# File 'lib/cron_format.rb', line 20

def initialize(cron_string, now=Time.now, debug: false)  
  @cron_string, @to_time, @debug = cron_string, now, debug
  parse()
end

Instance Attribute Details

#to_expressionObject (readonly)

Returns the value of attribute to_expression.



18
19
20
# File 'lib/cron_format.rb', line 18

def to_expression
  @to_expression
end

#to_timeObject (readonly)

Returns the value of attribute to_time.



18
19
20
# File 'lib/cron_format.rb', line 18

def to_time
  @to_time
end

Instance Method Details

#adjust_date(d) ⇒ Object

supply a Time object. Modifying the date can be helpful when triggering a day before an actual expression date e.g. the day before the last sunday in March (British summer time).



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cron_format.rb', line 29

def adjust_date(d)
  
  @to_time = d
  m, h, dd, mm, yy = @to_expression.split
  
  day = dd =~ /^\d+$/ ? d.day : dd
  month = mm =~ /^\d+$/  ? d.month : mm
  year = yy =~ /^\d+$/ ? d.year : yy
  
  @to_expression = [m, h, day, month, year].join(' ')
  
end

#nextObject



42
43
44
45
46
47
# File 'lib/cron_format.rb', line 42

def next()
  
  nudge() #unless @cron_string =~ %r{/}
  #puts ':to_time : ' + @to_time.inspect
  parse()
end