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.
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 47 48 49 50 51 52 53 54 |
# File 'lib/chronic_cron.rb', line 22 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 @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 |
Class Method Details
.parse(s) ⇒ Object
17 18 19 20 |
# File 'lib/chronic_cron.rb', line 17 def self.parse(s) r = new(s) r.valid? ? r : nil end |
Instance Method Details
#in24hrs(raw_hrs, meridiem) ⇒ Object
453 454 455 456 457 458 459 460 |
# File 'lib/chronic_cron.rb', line 453 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
56 57 58 59 60 61 62 63 |
# File 'lib/chronic_cron.rb', line 56 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
65 66 67 |
# File 'lib/chronic_cron.rb', line 65 def next() @cf.next end |
#to_date ⇒ Object
69 70 71 |
# File 'lib/chronic_cron.rb', line 69 def to_date() @cf.to_time.to_date end |
#to_time ⇒ Object
73 74 75 |
# File 'lib/chronic_cron.rb', line 73 def to_time() @cf.to_time end |
#valid? ⇒ Boolean
77 78 79 |
# File 'lib/chronic_cron.rb', line 77 def valid? @cf.respond_to? :to_time end |