lib/fugit/nat.rb in fugit-1.3.0 vs lib/fugit/nat.rb in fugit-1.3.1
- old
+ new
@@ -35,28 +35,31 @@
protected
def parse_crons(s, a, opts)
- dhs, aa =
- a.partition { |e| e[0] == :digital_hour }
- dms =
- dhs.collect { |dh| dh[1][1] }.uniq
+ dhs, aa = a
+ .partition { |e| e[0] == :digital_hour }
+ ms = dhs
+ .inject({}) { |h, dh| (h[dh[1][0]] ||= []) << dh[1][1]; h }
+ .values
+ .uniq
crons =
- if dhs.empty? || dms.size == 1
+ #if ms.size <= 1 || hs.size <= 1
+ if ms.size <= 1
[ parse_cron(a, opts) ]
else
dhs.collect { |dh| parse_cron([ dh ] + aa, opts) }
end
fail ArgumentError.new(
"multiple crons in #{s.inspect} " +
"(#{crons.collect(&:original).join(' | ')})"
) if opts[:multi] == :fail && crons.size > 1
- if opts[:multi]
+ if opts[:multi] == true || (opts[:multi] && opts[:multi] != :fail)
crons
else
crons.first
end
end
@@ -82,23 +85,27 @@
h[:tz] = val
elsif key == :duration
process_duration(h, *val[0].to_h.first)
end
end
+
h[:min] ||= [ 0 ]
h[:min].uniq!
- h[:hou].sort! if h[:hou]
+
+ h[:hou].uniq!;
+ h[:hou].sort!
+
h[:dow].sort! if h[:dow]
a = hkeys
.collect { |k|
v = h[k]
(v && v.any?) ? v.collect(&:to_s).join(',') : '*' }
a.insert(0, h[:sec]) if h[:sec]
a << h[:tz].first if h[:tz]
+
s = a.join(' ')
-#p s
Fugit::Cron.parse(s)
end
def process_duration(h, interval, value)