Class: Chrono::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/chrono/schedule.rb

Constant Summary collapse

TABLE =
{
  '@yearly'   => %w"0 0 1 1 *",
  '@annually' => %w"0 0 1 1 *",
  '@monthly'  => %w"0 0 1 * *",
  '@weekly'   => %w"0 0 * * 0",
  '@daily'    => %w"0 0 * * *",
  '@hourly'   => %w"0 * * * *",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Schedule

Returns a new instance of Schedule.



13
14
15
16
17
18
19
# File 'lib/chrono/schedule.rb', line 13

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

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'lib/chrono/schedule.rb', line 3

def source
  @source
end

Instance Method Details

#daysObject



29
30
31
# File 'lib/chrono/schedule.rb', line 29

def days
  Fields::Day.new(fields[2]).to_a
end

#days?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/chrono/schedule.rb', line 41

def days?
  fields[2] != '*'
end

#hoursObject



25
26
27
# File 'lib/chrono/schedule.rb', line 25

def hours
  Fields::Hour.new(fields[1]).to_a
end

#last_day_of_month?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/chrono/schedule.rb', line 49

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

#minutesObject



21
22
23
# File 'lib/chrono/schedule.rb', line 21

def minutes
  Fields::Minute.new(fields[0]).to_a
end

#monthsObject



33
34
35
# File 'lib/chrono/schedule.rb', line 33

def months
  Fields::Month.new(fields[3]).to_a
end

#wdaysObject



37
38
39
# File 'lib/chrono/schedule.rb', line 37

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

#wdays?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/chrono/schedule.rb', line 45

def wdays?
  fields[4] != '*'
end