Class: Colonel::Parser::TimeParser
- Inherits:
-
Object
- Object
- Colonel::Parser::TimeParser
- Defined in:
- lib/colonel/parser.rb
Overview
Class to parse time fields from crontab line.
Constant Summary collapse
- DIGIT =
/\d{1,2}/
- ALL =
/\*/
- COMMA =
/\,/
- DASH =
/\-/
- RANGE =
/#{DIGIT}#{DASH}#{DIGIT}/
- DEVIDE =
/#{ALL}\/#{DIGIT}|#{RANGE}\/#{DIGIT}/
- DEVIDER =
/\//
Instance Method Summary collapse
- #ast ⇒ Object
-
#initialize(time_expression, time_type, all_flag = true) ⇒ TimeParser
constructor
if all_flag is true -> return :all result if all?.
- #max_time_value ⇒ Object
- #min_time_value ⇒ Object
- #result ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(time_expression, time_type, all_flag = true) ⇒ TimeParser
if all_flag is true -> return :all result if all?
125 126 127 128 129 |
# File 'lib/colonel/parser.rb', line 125 def initialize(time_expression, time_type, all_flag=true) @time_type = time_type @tokens = time_expression.scan(/#{COMMA}|#{DEVIDE}|#{RANGE}|#{DIGIT}|#{ALL}/) @all_flag = all_flag end |
Instance Method Details
#ast ⇒ Object
131 132 133 |
# File 'lib/colonel/parser.rb', line 131 def ast @_ast ||= expression end |
#max_time_value ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/colonel/parser.rb', line 160 def max_time_value @_max_time_value ||= case @time_type when :minute 59 when :hour 23 when :day 31 when :month 12 when :weekday 6 end end |
#min_time_value ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/colonel/parser.rb', line 145 def min_time_value @_min_time_value ||= case @time_type when :minute 0 when :hour 0 when :day 1 when :month 1 when :weekday 0 end end |
#result ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/colonel/parser.rb', line 135 def result unique = ast.flatten.uniq unique.pop if unique.last.nil? #remove nil element if all?(unique) && @all_flag :all else unique end end |
#tokens ⇒ Object
120 121 122 |
# File 'lib/colonel/parser.rb', line 120 def tokens @tokens end |