lib/fugit/cron.rb in fugit-0.9.2 vs lib/fugit/cron.rb in fugit-0.9.3
- old
+ new
@@ -262,10 +262,12 @@
def init(original, h)
@original = original
+ h ||= {}
+
determine_minutes(h[:min])
determine_hours(h[:hou])
determine_monthdays(h[:dom])
determine_months(h[:mon])
determine_weekdays(h[:dow])
@@ -300,32 +302,38 @@
arr.uniq!
arr.sort!
end
def determine_minutes(mins)
+ return @minutes = nil unless mins
@minutes = mins.inject([]) { |a, r| a.concat(expand(0, 59, r)) }
compact(:@minutes)
end
def determine_hours(hous)
+ return @hours = nil unless hous
@hours = hous.inject([]) { |a, r| a.concat(expand(0, 23, r)) }
@hours = @hours.collect { |h| h == 24 ? 0 : h }
compact(:@hours)
end
def determine_monthdays(doms)
+ return @monthdays = nil unless doms
@monthdays = doms.inject([]) { |a, r| a.concat(expand(1, 31, r)) }
compact(:@monthdays)
end
def determine_months(mons)
+ return @months = nil unless mons
@months = mons.inject([]) { |a, r| a.concat(expand(1, 12, r)) }
compact(:@months)
end
def determine_weekdays(dows)
+ return @weekdays = nil unless dows
+
@weekdays = dows.inject([]) { |a, r|
aa = expand(0, 7, r)
if hsh = r[3]
a.concat([ [ aa.first, hsh ] ])
else
@@ -344,11 +352,13 @@
end
end
module Parser include Raabro
- WEEKDAYS = %w[ sun mon tue wed thu fri sat ]
+ WEEKDAYS = %w[ sunday monday tuesday wednesday thursday friday saturday ]
+ WEEKDS = WEEKDAYS.collect { |d| d[0, 3] }
+
MONTHS = %w[ - jan feb mar apr may jun jul aug sep oct nov dec ]
# piece parsers bottom to top
def s(i); rex(:s, i, /[ \t]+/); end
@@ -360,11 +370,11 @@
def core_min(i); rex(:min, i, /[0-5]?\d/); end
def core_hou(i); rex(:hou, i, /(2[0-4]|[01]?[0-9])/); end
def core_dom(i); rex(:dom, i, /(-?(3[01]|[012]?[0-9])|last|l)/i); end
def core_mon(i); rex(:mon, i, /(1[0-2]|0?[0-9]|#{MONTHS[1..-1].join('|')})/i); end
- def core_dow(i); rex(:dow, i, /([0-7]|#{WEEKDAYS.join('|')})/i); end
+ def core_dow(i); rex(:dow, i, /([0-7]|#{WEEKDS.join('|')})/i); end
def dow_hash(i); rex(:hash, i, /#(-?[1-5]|last|l)/i); end
def min(i); core_min(i); end
def hou(i); core_hou(i); end
@@ -422,10 +432,10 @@
def to_i(k, t)
s = t.string.downcase
(k == :mon && MONTHS.index(s)) ||
- (k == :dow && WEEKDAYS.index(s)) ||
+ (k == :dow && WEEKDS.index(s)) ||
(k == :dom && s[0, 1] == 'l' && -1) || # L, l, last
s.to_i
end
def rewrite_entry(t)