Class: CronFormat
- Inherits:
-
Object
- Object
- CronFormat
- Defined in:
- lib/cron_format.rb
Instance Attribute Summary collapse
-
#to_expression ⇒ Object
readonly
Returns the value of attribute to_expression.
-
#to_time ⇒ Object
readonly
Returns the value of attribute to_time.
Instance Method Summary collapse
-
#adjust_date(d) ⇒ Object
supply a Time object.
-
#initialize(cron_string, now = Time.now, debug: false) ⇒ CronFormat
constructor
A new instance of CronFormat.
- #next ⇒ Object
Constructor Details
#initialize(cron_string, now = Time.now, debug: false) ⇒ CronFormat
Returns a new instance of CronFormat.
22 23 24 25 26 27 28 29 |
# File 'lib/cron_format.rb', line 22 def initialize(cron_string, now=Time.now, debug: false) puts 'inside CronFormat'.info if debug @cron_string, @now, @debug = cron_string, now, debug @to_time = @now parse() end |
Instance Attribute Details
#to_expression ⇒ Object (readonly)
Returns the value of attribute to_expression.
20 21 22 |
# File 'lib/cron_format.rb', line 20 def to_expression @to_expression end |
#to_time ⇒ Object (readonly)
Returns the value of attribute to_time.
20 21 22 |
# File 'lib/cron_format.rb', line 20 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).
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cron_format.rb', line 35 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 |
#next ⇒ Object
48 49 50 51 52 53 |
# File 'lib/cron_format.rb', line 48 def next() nudge() #unless @cron_string =~ %r{/} #puts ':to_time : ' + @to_time.inspect parse(nudged: true) end |