Class: Ponder::Callback
- Inherits:
-
Object
- Object
- Ponder::Callback
- Defined in:
- lib/ponder/callback.rb
Direct Known Subclasses
Constant Summary collapse
- LISTENED_TYPES =
+ 3-digit numbers
[:connect, :channel, :query, :join, :part, :quit, :nickchange, :kick, :topic, :disconnect]
Instance Method Summary collapse
- #call(event_type, event_data = {}) ⇒ Object
-
#initialize(event_type = :channel, match = //, proc = Proc.new {}) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(event_type = :channel, match = //, proc = Proc.new {}) ⇒ Callback
Returns a new instance of Callback.
5 6 7 8 9 10 11 12 |
# File 'lib/ponder/callback.rb', line 5 def initialize(event_type = :channel, match = //, proc = Proc.new {}) unless self.class::LISTENED_TYPES.include?(event_type) || event_type.is_a?(Integer) raise TypeError, "#{event_type} is an unsupported event-type" end self.match = match self.proc = proc end |
Instance Method Details
#call(event_type, event_data = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/ponder/callback.rb', line 14 def call(event_type, event_data = {}) if (event_type == :channel) || (event_type == :query) @proc.call(event_data) if event_data[:message] =~ @match elsif event_type == :topic @proc.call(event_data) if event_data[:topic] =~ @match else @proc.call(event_data) end end |