class Ellen::Action
Attributes
options[R]
pattern[R]
Public Class Methods
new(pattern, options = {})
click to toggle source
# File lib/ellen/action.rb, line 9 def initialize(pattern, options = {}) @pattern = pattern @options = options end
prefix_pattern(robot_name)
click to toggle source
# File lib/ellen/action.rb, line 3 def self.prefix_pattern(robot_name) /\A@?#{Regexp.escape(robot_name)}:?\s*/ end
Public Instance Methods
<=>(action)
click to toggle source
# File lib/ellen/action.rb, line 34 def <=>(action) pattern.to_s <=> action.pattern.to_s end
all?()
click to toggle source
# File lib/ellen/action.rb, line 18 def all? !!options[:all] end
call(handler, message)
click to toggle source
# File lib/ellen/action.rb, line 14 def call(handler, message) handler.send(name, message) if message.match pattern_with(handler.robot.name) end
description()
click to toggle source
# File lib/ellen/action.rb, line 22 def description options[:description] || "(no description)" end
name()
click to toggle source
# File lib/ellen/action.rb, line 30 def name options[:name] end
Private Instance Methods
pattern_with(robot_name)
click to toggle source
# File lib/ellen/action.rb, line 40 def pattern_with(robot_name) if all? /\A#{pattern}/ else /#{self.class.prefix_pattern(robot_name)}#{pattern}/ end end