Sha256: 758671b20e76ac8ae3f18aee1b04bcb0aea1e13c8576d07ae5b5739653ca9042
Contents?: true
Size: 856 Bytes
Versions: 5
Compression:
Stored size: 856 Bytes
Contents
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) handler.send(name, message) if message.match pattern_with(handler.robot.name) end def all? !!options[:all] end def description options[:description] || "(no description)" end def hidden? !!options[:hidden] 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
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
ruboty-1.0.4 | lib/ruboty/action.rb |
ruboty-1.0.3 | lib/ruboty/action.rb |
ruboty-1.0.2 | lib/ruboty/action.rb |
ruboty-1.0.1 | lib/ruboty/action.rb |
ruboty-1.0.0 | lib/ruboty/action.rb |