Class: CrontabParser::Record
- Inherits:
-
Object
- Object
- CrontabParser::Record
- Defined in:
- lib/crontab-parser/record.rb
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #cmd ⇒ Object
-
#initialize(line, options = {}) ⇒ Record
constructor
A new instance of Record.
- #should_run?(time) ⇒ Boolean
- #times ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(line, options = {}) ⇒ Record
Returns a new instance of Record.
7 8 9 10 |
# File 'lib/crontab-parser/record.rb', line 7 def initialize(line, ={}) @line = line @options = end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
5 6 7 |
# File 'lib/crontab-parser/record.rb', line 5 def line @line end |
Instance Method Details
#cmd ⇒ Object
12 13 14 15 |
# File 'lib/crontab-parser/record.rb', line 12 def cmd times @cmd end |
#should_run?(time) ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/crontab-parser/record.rb', line 21 def should_run?(time) time.utc times[:min].include?(time.min) && times[:hour].include?(time.hour) && times[:day].include?(time.day) && times[:month].include?(time.month) && times[:week].include?(time.wday) end |
#times ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/crontab-parser/record.rb', line 30 def times @times ||= begin base = @line.strip.gsub(/#.*/, "").gsub(%r!^@(yearly|annually|monthly|weekly|daily|midnight|hourly)!){|m| case $1 when 'yearly','annually' '0 0 1 1 *' when 'monthly' '0 0 1 * *' when 'weekly' '0 0 * * 0' when 'daily','midnight' '0 0 * * *' when 'hourly' '0 * * * *' end }.strip min,hour,day,month,week,@cmd = *base.split(/[\t\s]+/, 6) base = [min,hour,day,month,week].join(" ") if week.nil? if @options[:silent] return nil else raise "invalid line #{@line}" end end { :month => TimeParser.parse(month, 1, 12), :day => TimeParser.parse(day, 1, 31), :hour => TimeParser.parse(hour, 0, 23), :min => TimeParser.parse(min, 0, 59), :week => TimeParser.parse(week, 0, 6), } end end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/crontab-parser/record.rb', line 17 def to_s @line end |