Module: Asyncron::Cron
Constant Summary collapse
- MINUTE =
(0..59).to_a
- HOUR =
(0..23).to_a
- MONTHDAY =
(1..31).to_a
- MONTH =
(1..12).to_a
- WEEKDAY =
(1..7).to_a
- YEAR =
(1900..3000).to_a
- POSITION =
%w(minute hour monthday month weekday year)
Instance Method Summary collapse
Instance Method Details
#parse(expr) ⇒ Object
16 17 18 |
# File 'lib/asyncron/cron.rb', line 16 def parse(expr) expr.split(/[\s\t]+/).map.with_index { |e, i| transform(i, e) } end |
#transform(pos, value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/asyncron/cron.rb', line 24 def transform(pos, value) unless validate(value) raise ArgumentError.new("invalid format for #{POSITION[pos]}") end return divide(value) do |no_divide| range = single_num(no_divide) || extend_asterisk(pos, value) next range if range next filter((pos), value) end end |
#validate(value) ⇒ Object
20 21 22 |
# File 'lib/asyncron/cron.rb', line 20 def validate(value) value =~ /^((\d+(-\d+)?(,\d+(-\d+)?)*)(\/\d+)?|\*(\/\d+)?)$/ end |