Sha256: 566a33a532c6a2d6b1d80fe4276f66d94c14ea65a96c06ba8a78ebaa15f6f547

Contents?: true

Size: 553 Bytes

Versions: 1

Compression:

Stored size: 553 Bytes

Contents

module Ellen
  class Action
    attr_reader :block, :options, :pattern

    def initialize(pattern, options = {}, &block)
      @pattern = pattern
      @options = options
      @block = block
    end

    def call(handler, message)
      handler.robot.instance_exec(message, &block) if message.match pattern_with(handler.robot.name)
    end

    def all?
      !!options[:all]
    end

    private

    def pattern_with(name)
      if all?
        /\A#{pattern}/
      else
        /\A@?#{Regexp.escape(name)}\s*#{pattern}/
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ellen-0.0.5 lib/ellen/action.rb