Class: Ruboty::Action
- Inherits:
-
Object
- Object
- Ruboty::Action
- Defined in:
- lib/ruboty/action.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(action) ⇒ Object
- #all? ⇒ Boolean
- #call(handler, message, options = {}) ⇒ Object
- #description ⇒ Object
- #hidden? ⇒ Boolean
-
#initialize(pattern, options = {}) ⇒ Action
constructor
A new instance of Action.
- #missing? ⇒ Boolean
- #name ⇒ Object
Constructor Details
#initialize(pattern, options = {}) ⇒ Action
Returns a new instance of Action.
9 10 11 12 |
# File 'lib/ruboty/action.rb', line 9 def initialize(pattern, = {}) @pattern = pattern @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/ruboty/action.rb', line 7 def @options end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/ruboty/action.rb', line 7 def pattern @pattern end |
Class Method Details
.prefix_pattern(robot_name) ⇒ Object
3 4 5 |
# File 'lib/ruboty/action.rb', line 3 def self.prefix_pattern(robot_name) /\A@?#{Regexp.escape(robot_name)}:?[[:space:]]+/ end |
Instance Method Details
#<=>(action) ⇒ Object
43 44 45 |
# File 'lib/ruboty/action.rb', line 43 def <=>(action) pattern.to_s <=> action.pattern.to_s end |
#all? ⇒ Boolean
22 23 24 |
# File 'lib/ruboty/action.rb', line 22 def all? !![:all] end |
#call(handler, message, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ruboty/action.rb', line 14 def call(handler, , = {}) if !![:missing] == missing? && .match(pattern_with(handler.robot.name)) !!handler.send(name, ) else false end end |
#description ⇒ Object
26 27 28 |
# File 'lib/ruboty/action.rb', line 26 def description [:description] || "(no description)" end |
#hidden? ⇒ Boolean
30 31 32 |
# File 'lib/ruboty/action.rb', line 30 def hidden? !![:hidden] end |
#missing? ⇒ Boolean
Note:
:missing action is called only when any handler doesn’t match given message.
35 36 37 |
# File 'lib/ruboty/action.rb', line 35 def missing? !![:missing] end |
#name ⇒ Object
39 40 41 |
# File 'lib/ruboty/action.rb', line 39 def name [:name] end |