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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/raketab.rb', line 31
def run(command, options={})
month, wday, mday, hour, min = options[:month] || options[:months] || options[:mon],
options[:weekday] || options[:weekdays] || options[:wday],
options[:day] || options[:days] || options[:mday],
options[:hour] || options[:hours],
options[:minute] || options[:minutes] || options[:min]
month, wday = [[month, Month], [wday, Weekday]].map do |element,type|
if element.kind_of?(Array) element.each_with_index { |e,i| element[i] = enum_to_i(e,type) }
else
enum_to_i(element,type)
end
end
[:each, :every, :on, :in, :at, :the].each do |type|
if options[type]
if(options[type] =~ /:/)
from = options[type]
else
from, ignore, exclusive, to = options[type].to_s.match(/(\w+)(\.\.(\.?)(\w+))?/)[1..4].map { |m| m.gsub(/s$/i, '') if m }
end
parse = Date._parse(from)
range = to ? Date._parse(to) : {}
month ||= get_value(parse, range, exclusive == '.', :mon)
wday ||= get_value(parse, range, exclusive == '.', :wday)
mday ||= get_value(parse, range, exclusive == '.', :mday)
hour ||= get_value(parse, range, exclusive == '.', :hour)
min ||= get_value(parse, range, exclusive == '.', :min)
end
end
min, hour, mday, wday, month = [min, hour, mday, wday, month].map do |type|
type.respond_to?(:map) ? type.map.join(',') : type
end
hour ||= options[:at].to_i if options[:at]
hour, min = [hour, min].map { |t| t || '0' }
month, wday, mday = [month, wday, mday].map { |t| t || '*' }
@tabs << "#{min} #{hour} #{mday} #{month} #{wday} #{command}"
end
|