Class: ChronicCron

Inherits:
Object
  • Object
show all
Includes:
AppRoutes
Defined in:
lib/chronic_cron.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_expressionObject (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

#inspectObject



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

#nextObject



53
54
55
# File 'lib/chronic_cron.rb', line 53

def next()
  @cf.next
end

#to_dateObject



57
58
59
# File 'lib/chronic_cron.rb', line 57

def to_date() 
  @cf.to_time.to_date
end

#to_timeObject



61
62
63
# File 'lib/chronic_cron.rb', line 61

def to_time()
  @cf.to_time
end