Class: Fugit::Nat::SlotGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/fugit/nat.rb

Instance Method Summary collapse

Constructor Details

#initialize(slots) ⇒ SlotGroup

Returns a new instance of SlotGroup.



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# 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

Instance Method Details

#to_crons(opts) ⇒ Object



635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# 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, opts) }
  else
    parse_cron(hms.first, opts)
  end
end