Class: CrontabLine
- Inherits:
-
CrontabLineBase
- Object
- CrontabLineBase
- CrontabLine
- Defined in:
- lib/crontab_line.rb
Constant Summary collapse
- @@ENTRY_REGEX =
/^([-\/,0-9*]+)\s+([-\/,0-9*]+)\s+([-\/,0-9*]+)\s+([-\/,0-9*]+)\s+([-\/,0-9*]+)\s+(.*)$/- @@MINUTE_GROUP_NUM =
1- @@HOUR_GROUP_NUM =
2- @@DAY_GROUP_NUM =
3- @@MONTH_GROUP_NUM =
4- @@WEEKDAY_GROUP_NUM =
5- @@COMMAND_GROUP_NUM =
6- @@SPACE_IN_LIST_REGEX =
/\d+(-\d+(\/\d+)?)?,\s\d+/
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CrontabLine
constructor
A new instance of CrontabLine.
- #to_s ⇒ Object
Methods inherited from CrontabLineBase
cron_attr_accessor, make_cron_attr
Constructor Details
#initialize ⇒ CrontabLine
Returns a new instance of CrontabLine.
18 19 20 21 22 23 24 25 26 |
# File 'lib/crontab_line.rb', line 18 def initialize @minute = [CrontabAsterisk.new] @hour = [CrontabAsterisk.new] @day = [CrontabAsterisk.new] @month = [CrontabAsterisk.new] @weekday = [CrontabAsterisk.new] @command = "" @user = nil end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/crontab_line.rb', line 8 def command @command end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/crontab_line.rb', line 7 def user @user end |
Class Method Details
.create_by_entry(entry) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/crontab_line.rb', line 39 def self.create_by_entry(entry) md = @@SPACE_IN_LIST_REGEX.match(entry) if md raise "I think you have a space in a crontab field (but I'm not very smart). " + "Use 'create_by_hash()' instead to override me." end md = @@ENTRY_REGEX.match(entry) if md crontab = CrontabLine.new crontab.minute = md[@@MINUTE_GROUP_NUM] crontab.hour = md[@@HOUR_GROUP_NUM] crontab.day = md[@@DAY_GROUP_NUM] crontab.month = md[@@MONTH_GROUP_NUM] crontab.weekday = md[@@WEEKDAY_GROUP_NUM] crontab.command = md[@@COMMAND_GROUP_NUM] crontab else raise "Entry did match expected pattern" end end |
.create_by_hash(crontab_hash) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/crontab_line.rb', line 32 def self.create_by_hash(crontab_hash) crontab = CrontabLine.new crontab_hash.each() do |key, value| crontab.send("#{key}=", value) end crontab end |
Instance Method Details
#to_s ⇒ Object
59 60 61 62 63 |
# File 'lib/crontab_line.rb', line 59 def to_s fields = [minute, hour, day, month, weekday, command] fields.insert(-2, user) unless user.nil? fields.join(" ") end |