module Ruboty
  class Action
    def self.prefix_pattern(robot_name)
      /\A@?#{Regexp.escape(robot_name)}:?\s+/
    end

    attr_reader :options, :pattern

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

    def call(handler, message, options = {})
      if !!options[:missing] == missing? && message.match(pattern_with(handler.robot.name))
        !!handler.send(name, message)
      else
        false
      end
    end

    def all?
      !!options[:all]
    end

    def description
      options[:description] || "(no description)"
    end

    def hidden?
      !!options[:hidden]
    end

    # @note :missing action is called only when any handler doesn't match given message.
    def missing?
      !!options[:missing]
    end

    def name
      options[:name]
    end

    def <=>(action)
      pattern.to_s <=> action.pattern.to_s
    end

    private

    def pattern_with(robot_name)
      if all?
        /\A#{pattern}/
      else
        /#{self.class.prefix_pattern(robot_name)}#{pattern}/
      end
    end
  end
end

module Ruboty
  class Action
    def self.prefix_pattern(robot_name)
      /\A@?#{Regexp.escape(robot_name)}:?[[:space:]]+/
    end

    attr_reader :options, :pattern

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

    def call(handler, message, options = {})
      if !!options[:missing] == missing? && message.match(pattern_with(handler.robot.name))
        !!handler.send(name, message)
      else
        false
      end
    end

    def all?
      !!options[:all]
    end

    def description
      options[:description] || "(no description)"
    end

    def hidden?
      !!options[:hidden]
    end

    # @note :missing action is called only when any handler doesn't match given message.
    def missing?
      !!options[:missing]
    end

    def name
      options[:name]
    end

    def <=>(action)
      pattern.to_s <=> action.pattern.to_s
    end

    private

    def pattern_with(robot_name)
      if all?
        /\A#{pattern}/
      else
        /#{self.class.prefix_pattern(robot_name)}#{pattern}/
      end
    end
  end
end

Support unicode spaces like U+00a0
Support unicode spaces like U+00a0

On some platform, spaces may be converted to Unicode spaces, and
`\s+` is not matched with such Unicode spaces.

This patch just changes regex pattern from `\s` to `[[:space:]]`.

I confirmed that Slack on Mac OS X will convert `"  "` to `" \u{00a0}"`
automatically on copy-and-past.
