Class: ChronicCron
Instance Attribute Summary collapse
-
#to_expression ⇒ Object
readonly
Returns the value of attribute to_expression.
Class Method Summary collapse
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
- #valid? ⇒ Boolean
Constructor Details
#initialize(s, now = Time.now, log: nil, debug: false) ⇒ ChronicCron
Returns a new instance of ChronicCron.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chronic_cron.rb', line 24 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+/,'')) puts 'expression: ' + expression.inspect if @debug return unless expression puts 'now: ' + now.inspect if @debug @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.
17 18 19 |
# File 'lib/chronic_cron.rb', line 17 def to_expression @to_expression end |
Class Method Details
.parse(s) ⇒ Object
19 20 21 22 |
# File 'lib/chronic_cron.rb', line 19 def self.parse(s) r = new(s) r.valid? ? r : nil end |
Instance Method Details
#in24hrs(raw_hrs, meridiem) ⇒ Object
468 469 470 471 472 473 474 475 476 477 |
# File 'lib/chronic_cron.rb', line 468 def in24hrs(raw_hrs, meridiem) puts 'raw_hrs: ' + raw_hrs.inspect if @debug hrs = if meridiem == 'pm' then raw_hrs.to_i < 12 ? raw_hrs.to_i + 12 : raw_hrs.to_i else raw_hrs.to_i == 12 ? 0 : raw_hrs end end |
#inspect ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/chronic_cron.rb', line 58 def inspect() if @cf then "#<ChronicCron:%s @to_expression=\"%s\", @to_time=\"%s\">" % [self.object_id, @to_expression, @cf.to_time] else "#<ChronicCron:%s >" % [self.object_id] end end |
#next ⇒ Object
67 68 69 |
# File 'lib/chronic_cron.rb', line 67 def next() @cf.next end |
#to_date ⇒ Object
71 72 73 |
# File 'lib/chronic_cron.rb', line 71 def to_date() @cf.to_time.to_date end |
#to_time ⇒ Object
75 76 77 |
# File 'lib/chronic_cron.rb', line 75 def to_time() @cf.to_time end |
#valid? ⇒ Boolean
79 80 81 |
# File 'lib/chronic_cron.rb', line 79 def valid? @cf.respond_to? :to_time end |