class Fugit::Nat::SlotGroup
Public Class Methods
new(slots)
click to toggle source
# File lib/fugit/nat.rb, line 610 def initialize(slots) #puts "SlotGroup.new " + slots.inspect @slots = {} @hms = [] slots.each do |s| if s.key == :hm #ls = @hms.last; @hms.pop if ls && ls.key == :hm && ls.weak == true @hms << s elsif hs = @slots[s.key] hs.append(s) else @slots[s.key] = s end end if @slots[:monthday] || @slots[:weekday] @hms << make_slot(:hm, 0, 0) if @hms.empty? elsif @slots[:month] @hms << make_slot(:hm, 0, 0) if @hms.empty? @slots[:monthday] ||= make_slot(:monthday, 1) end end
Public Instance Methods
to_crons(opts)
click to toggle source
# File lib/fugit/nat.rb, line 635 def to_crons(opts) multi = opts.has_key?(:multi) ? opts[:multi] : false hms = determine_hms if multi == :fail && hms.count > 1 fail(ArgumentError.new( "multiple crons in #{opts[:_s].inspect} - #{@slots.inspect}")) elsif multi == true hms.collect { |hm| parse_cron(hm) } else parse_cron(hms.first) end end
Protected Instance Methods
determine_hms()
click to toggle source
# File lib/fugit/nat.rb, line 658 def determine_hms return [ [ [ '*' ], [ '*' ] ] ] if @hms.empty? hms = @hms.dup # while ig = (hms.count > 1 && hms.index { |hm| hm.graded? }) do sg = hms[ig] so = hms.delete_at(ig == 0 ? 1 : ig - 1) sg.append(so) end hms .collect(&:a) .inject({}) { |r, hm| hm[1].each { |m| (r[m] ||= []).concat(hm[0]) } r } .inject({}) { |r, (m, hs)| (r[hs.sort] ||= []) << m r } .to_a end
make_slot(key, data0, data1=nil)
click to toggle source
# File lib/fugit/nat.rb, line 653 def make_slot(key, data0, data1=nil) Fugit::Nat::Slot.new(key, data0, data1) end
parse_cron(hm)
click to toggle source
# File lib/fugit/nat.rb, line 681 def parse_cron(hm) a = [ slot(:second, '0'), hm[1], hm[0], slot(:monthday, '*'), slot(:month, '*'), slot(:weekday, '*') ] tz = @slots[:tz] a << tz.data0 if tz a.shift if a.first == [ '0' ] s = a .collect { |e| e.uniq.sort.collect(&:to_s).join(',') } .join(' ') Fugit::Cron.parse(s) end
slot(key, default)
click to toggle source
# File lib/fugit/nat.rb, line 701 def slot(key, default) s = @slots[key] s ? s.data0 : [ default ] end