Class: CloudwatchChrono::Schedule

Inherits:
Chrono::Schedule
  • Object
show all
Defined in:
lib/cloudwatch_chrono/schedule.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Schedule

Returns a new instance of Schedule.



5
6
7
8
9
10
# File 'lib/cloudwatch_chrono/schedule.rb', line 5

def initialize(source)
  if %r<\A[ \t]*(?:(?<field>\S+)[ \t]+){5}\g<field>[ \t]*\z> !~ source
    raise Chrono::Fields::Base::InvalidField.new('invalid source', source)
  end
  @source = source
end

Instance Method Details

#days?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cloudwatch_chrono/schedule.rb', line 20

def days?
  !%w[* ?].include?(fields[2])
end

#last_day?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cloudwatch_chrono/schedule.rb', line 28

def last_day?
  fields[2] == 'L'
end

#latest_weekdayObject



32
33
34
# File 'lib/cloudwatch_chrono/schedule.rb', line 32

def latest_weekday
  fields[2].slice(/\A(\d+)W\z/, 1)
end

#ordered_weekdayObject

e.g. 3#2 means the second Tuesday and returns [3, 2]



37
38
39
40
41
42
# File 'lib/cloudwatch_chrono/schedule.rb', line 37

def ordered_weekday
  m = fields[2].match(/\A([0-6])#([1-5])\z/)
  if m
    m[1, 2].map(&:to_i)
  end
end

#wdaysObject



12
13
14
# File 'lib/cloudwatch_chrono/schedule.rb', line 12

def wdays
  Fields::Wday.new(fields[4]).to_a
end

#wdays?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cloudwatch_chrono/schedule.rb', line 24

def wdays?
  !%w[* ?].include?(fields[4])
end

#yearsObject



16
17
18
# File 'lib/cloudwatch_chrono/schedule.rb', line 16

def years
  Fields::Year.new(fields[5]).to_a
end