Class: ChronicCron
Instance Attribute Summary collapse
-
#to_expression ⇒ Object
readonly
Returns the value of attribute to_expression.
Instance Method Summary collapse
- #in24hrs(raw_hrs, meridiem) ⇒ Object
-
#initialize(s, now = Time.now, log: nil, debug: false) ⇒ ChronicCron
constructor
A new instance of ChronicCron.
- #inspect ⇒ Object
- #next ⇒ Object
- #to_date ⇒ Object
- #to_time ⇒ Object
Constructor Details
#initialize(s, now = Time.now, log: nil, debug: false) ⇒ ChronicCron
Returns a new instance of ChronicCron.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chronic_cron.rb', line 17 def initialize(s, now=Time.now, log: nil, debug: false) @now, @log, @debug = now, log, debug puts ('@now: ' + @now.inspect).debug if @debug super() @params = {input: s} expressions(@params) if s =~ /^tomorrow/i then s.sub!(/^tomorrow /i,'') expression = find_expression(s.downcase\ .sub(/^(?:is|on|at|from|starting)\s+/,'')) @cf = CronFormat.new(expression, now) @cf.adjust_date @cf.to_time - (24 * 60 * 60) else expression = find_expression(s.downcase\ .sub(/^(?:on|at|from|starting)\s+/,'')) @cf = CronFormat.new(expression, now) end @to_expression = @cf.to_expression end |
Instance Attribute Details
#to_expression ⇒ Object (readonly)
Returns the value of attribute to_expression.
15 16 17 |
# File 'lib/chronic_cron.rb', line 15 def to_expression @to_expression end |
Instance Method Details
#in24hrs(raw_hrs, meridiem) ⇒ Object
435 436 437 438 439 440 441 442 |
# File 'lib/chronic_cron.rb', line 435 def in24hrs(raw_hrs, meridiem) hrs = if meridiem == 'pm' then raw_hrs.to_i + 12 else raw_hrs.to_i == 12 ? 0 : raw_hrs end end |
#inspect ⇒ Object
48 49 50 51 |
# File 'lib/chronic_cron.rb', line 48 def inspect() "#<ChronicCron:%s @to_expression=\"%s\", @to_time=\"%s\">" % [self.object_id, @to_expression, @cf.to_time] end |
#next ⇒ Object
53 54 55 |
# File 'lib/chronic_cron.rb', line 53 def next() @cf.next end |
#to_date ⇒ Object
57 58 59 |
# File 'lib/chronic_cron.rb', line 57 def to_date() @cf.to_time.to_date end |
#to_time ⇒ Object
61 62 63 |
# File 'lib/chronic_cron.rb', line 61 def to_time() @cf.to_time end |