Class: OpenWFE::CronLine
- Inherits:
-
Object
- Object
- OpenWFE::CronLine
- Defined in:
- lib/openwfe/util/scheduler.rb
Overview
A ‘cron line’ is a line in the sense of a crontab (man 5 crontab) file line.
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#original ⇒ Object
readonly
The string used for creating this cronline instance.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
-
#weekdays ⇒ Object
readonly
Returns the value of attribute weekdays.
Instance Method Summary collapse
-
#initialize(line) ⇒ CronLine
constructor
A new instance of CronLine.
-
#matches?(time) ⇒ Boolean
Returns true if the given time matches this cron line.
-
#to_array ⇒ Object
Returns an array of 6 arrays (seconds, minutes, hours, days, months, weekdays).
Constructor Details
#initialize(line) ⇒ CronLine
Returns a new instance of CronLine.
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'lib/openwfe/util/scheduler.rb', line 1091 def initialize (line) super() @original = line items = line.split unless [ 5, 6 ].include?(items.length) raise \ "cron '#{line}' string should hold 5 or 6 items, " + "not #{items.length}" \ end offset = items.length - 5 @seconds = if offset == 1 parse_item(items[0], 0, 59) else [ 0 ] end @minutes = parse_item(items[0+offset], 0, 59) @hours = parse_item(items[1+offset], 0, 24) @days = parse_item(items[2+offset], 1, 31) @months = parse_item(items[3+offset], 1, 12) @weekdays = parse_weekdays(items[4+offset]) #adjust_arrays() end |
Instance Attribute Details
#days ⇒ Object (readonly)
Returns the value of attribute days.
1083 1084 1085 |
# File 'lib/openwfe/util/scheduler.rb', line 1083 def days @days end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
1083 1084 1085 |
# File 'lib/openwfe/util/scheduler.rb', line 1083 def hours @hours end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
1083 1084 1085 |
# File 'lib/openwfe/util/scheduler.rb', line 1083 def minutes @minutes end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
1083 1084 1085 |
# File 'lib/openwfe/util/scheduler.rb', line 1083 def months @months end |
#original ⇒ Object (readonly)
The string used for creating this cronline instance.
1081 1082 1083 |
# File 'lib/openwfe/util/scheduler.rb', line 1081 def original @original end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
1083 1084 1085 |
# File 'lib/openwfe/util/scheduler.rb', line 1083 def seconds @seconds end |
#weekdays ⇒ Object (readonly)
Returns the value of attribute weekdays.
1083 1084 1085 |
# File 'lib/openwfe/util/scheduler.rb', line 1083 def weekdays @weekdays end |
Instance Method Details
#matches?(time) ⇒ Boolean
Returns true if the given time matches this cron line.
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 |
# File 'lib/openwfe/util/scheduler.rb', line 1124 def matches? (time) time = Time.at(time) \ if time.kind_of?(Float) or time.kind_of?(Integer) return false if no_match?(time.sec, @seconds) return false if no_match?(time.min, @minutes) return false if no_match?(time.hour, @hours) return false if no_match?(time.day, @days) return false if no_match?(time.month, @months) return false if no_match?(time.wday, @weekdays) true end |
#to_array ⇒ Object
Returns an array of 6 arrays (seconds, minutes, hours, days, months, weekdays). This method is used by the cronline unit tests.
1144 1145 1146 |
# File 'lib/openwfe/util/scheduler.rb', line 1144 def to_array [ @seconds, @minutes, @hours, @days, @months, @weekdays ] end |