class Ruboty::Action
Attributes
options[R]
pattern[R]
Public Class Methods
new(pattern, options = {})
click to toggle source
# File lib/ruboty/action.rb, line 9 def initialize(pattern, options = {}) @pattern = pattern @options = options end
prefix_pattern(robot_name)
click to toggle source
# File lib/ruboty/action.rb, line 3 def self.prefix_pattern(robot_name) /\A@?#{Regexp.escape(robot_name)}:?[[:space:]]+/ end
Public Instance Methods
<=>(action)
click to toggle source
# File lib/ruboty/action.rb, line 43 def <=>(action) pattern.to_s <=> action.pattern.to_s end
all?()
click to toggle source
# File lib/ruboty/action.rb, line 22 def all? !!options[:all] end
call(handler, message, options = {})
click to toggle source
# File lib/ruboty/action.rb, line 14 def call(handler, message, options = {}) if !!options[:missing] == missing? && message.match(pattern_with(handler.robot.name)) !!handler.send(name, message) else false end end
description()
click to toggle source
# File lib/ruboty/action.rb, line 26 def description options[:description] || "(no description)" end
missing?()
click to toggle source
@note :missing action is called only when any handler doesn't match given message.
# File lib/ruboty/action.rb, line 35 def missing? !!options[:missing] end
name()
click to toggle source
# File lib/ruboty/action.rb, line 39 def name options[:name] end
Private Instance Methods
pattern_with(robot_name)
click to toggle source
# File lib/ruboty/action.rb, line 49 def pattern_with(robot_name) if all? /\A#{pattern}/ else /#{self.class.prefix_pattern(robot_name)}#{pattern}/ end end