Sha256: 02a1e13502e7f311101d5be1ec34fab462699883960743528b10b985ea7029d0

Contents?: true

Size: 692 Bytes

Versions: 7

Compression:

Stored size: 692 Bytes

Contents

require_relative 'rule_dsl'

module AutoResp

  class RuleManager

    include RuleDSL

    def initialize
    end

    def rules
      @rules ||= {}
    end

    def clear
      @rules.clear
    end

    def add_handler( handler )
      if @last_rule
        rules[@last_rule] = handler
      end
    end

    def add_rule(*args, &block)
      @last_rule = target = args.first
      case target
      when Hash
        @last_rule = target.keys.first
        rules.merge! target
      when String
        rules[target] = args[1]
      when Regexp
        if block_given?
          rules[target] = block
        else
          rules[target] = args[1]
        end
      end
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
auto_response-0.1.6 lib/ar/rule_manager.rb
auto_response-0.1.5 lib/ar/rule_manager.rb
auto_response-0.1.4 lib/ar/rule_manager.rb
auto_response-0.1.3 lib/ar/rule_manager.rb
auto_response-0.1.2 lib/ar/rule_manager.rb
auto_response-0.1.1 lib/ar/rule_manager.rb
auto_response-0.1.0 lib/ar/rule_manager.rb