Sha256: c2435635326177c84f8758b805e8b5b7a3bb74b7bf3bc10b96d688422dc96738

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

module Lomic

class Rule < Lomic
  def initialize(number)
    @number = number
    @event_bag = {} # "event_name" => [Event]
  end

  
  def event(event_name, options={}, &block)
    options[:priority] ||= 5
    options[:name] = event_name
    options[:block] = block
    
    event = Event.new(options)
    if @event_bag[event_name].nil?
      @event_bag[event_name] = [event]
    else
      # insert into sorted spot
      arr = @event_bag[event_name]
      i = 0
      arr.each do |e|
        if event.priority > e.priority
          arr.insert(i,event)
          break
        elsif i == arr.size-1
          arr.insert(i+1,event)
          break
        end
        i += 1
      end
    end
  end
  
  def event_bag
    @event_bag
  end
  
  def inspect
    "Rule #{@number}: #{@event_bag.inspect}"
  end
end

end # module

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lomic-0.0.2 lib/lomic/Rule.rb
lomic-0.0.1 lib/lomic/Rule.rb