Class: AWSCronParser::Parsers::AWSCron

Inherits:
Base
  • Object
show all
Defined in:
lib/aws_cron_parser/parsers/aws_cron.rb

Instance Attribute Summary

Attributes inherited from Base

#original_source, #source, #time_source, #time_zone

Instance Method Summary collapse

Methods inherited from Base

#last

Methods included from Helpers

included

Constructor Details

#initialize(source, time_source = Time) ⇒ AWSCron

Returns a new instance of AWSCron.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/aws_cron_parser/parsers/aws_cron.rb', line 8

def initialize(source, time_source = Time)
  super(source, time_source)

  @source = normalize_source(source)

  # Detect special patterns
  @has_nth_weekday = detect_pattern(@source, '#')
  @has_last_weekday = detect_pattern(@source, 'L')
  @has_last_day_of_month = detect_dom_pattern(@source, 'L')
  @has_weekday_closest = detect_dom_pattern(@source, 'W')
  @has_complex_step = detect_complex_step(@source)
  @weekday_only = weekday_only?(@source)
  @day_only = day_only?(@source)
end

Instance Method Details

#next(now = @time_source.now) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aws_cron_parser/parsers/aws_cron.rb', line 23

def next(now = @time_source.now)
  if @has_last_weekday
    calculate_next_last_weekday(now)
  elsif @has_nth_weekday
    calculate_next_nth_weekday(now)
  elsif @has_last_day_of_month || @has_weekday_closest || @day_only
    calculate_next_day_only(now)
  elsif @weekday_only
    calculate_next_weekday_only(now)
  elsif @has_complex_step || @source.split(/\s+/).length >= 5
    calculate_next_standard(now)
  else
    raise NotImplementedError, 'Unexpected AWS CRON pattern'
  end
end