Class: CronParser

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

Constant Summary collapse

SUBELEMENT_REGEX =
%r{^(\d+|l|w)((-(\d+)(/(\d+))?)?|#(\d+))$}

Instance Method Summary collapse

Instance Method Details

#parse_element(elem, allowed_range, time_specs_key = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cron_parse.rb', line 8

def parse_element(elem, allowed_range, time_specs_key=nil)
  values = elem.split(',').map do |subel|
    if subel =~ /^\*/
      step = subel.length > 1 ? subel[2..-1].to_i : 1
      stepped_range(allowed_range, step)
    else
      if SUBELEMENT_REGEX === subel
        if $6 # with range
          stepped_range($1.to_i..$4.to_i, $6.to_i)
        elsif $4 # range without step
          stepped_range($1.to_i..$4.to_i, 1)
        elsif $1 == "l" && time_specs_key == :dom
          [$1]
        elsif $1 == "w" && time_specs_key == :dow
          [1, 2, 3, 4, 5]
        else # just a numeric
          @dow_offset = $7.to_i if $7
          [$1.to_i]
        end
      else
        raise ArgumentError, "Bad Vixie-style specification #{subel}"
      end
    end
  end.flatten

  values = values.sort if time_specs_key.nil?
  [Set.new(values), values, elem]
end