Class: SardonyxRing::Handlers::MessageHandler
- Inherits:
-
Object
- Object
- SardonyxRing::Handlers::MessageHandler
- Defined in:
- lib/sardonyx_ring/handlers/message_handler.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern, callback) ⇒ MessageHandler
constructor
A new instance of MessageHandler.
- #match(message) ⇒ Object
- #run(app, message_event, match = nil) ⇒ Object
Constructor Details
#initialize(pattern, callback) ⇒ MessageHandler
Returns a new instance of MessageHandler.
6 7 8 9 |
# File 'lib/sardonyx_ring/handlers/message_handler.rb', line 6 def initialize(pattern, callback) @pattern = pattern @callback = callback end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
11 12 13 |
# File 'lib/sardonyx_ring/handlers/message_handler.rb', line 11 def pattern @pattern end |
Instance Method Details
#match(message) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/sardonyx_ring/handlers/message_handler.rb', line 18 def match() case @pattern when String @pattern if .text == @pattern when Regexp .text&.match(@pattern) end end |
#run(app, message_event, match = nil) ⇒ Object
13 14 15 16 |
# File 'lib/sardonyx_ring/handlers/message_handler.rb', line 13 def run(app, , match = nil) args = [, match].slice(0, @callback.arity) @callback.bind(app).call(*args) end |