Class: Ponder::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/ponder/callback.rb

Direct Known Subclasses

Filter

Constant Summary collapse

LISTENED_TYPES =

+ 3-digit numbers

[:connect, :channel, :query, :join, :part, :quit, :nickchange, :kick, :topic, :disconnect]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type = :channel, match = //, options = {}, proc = Proc.new {}) ⇒ Callback

Returns a new instance of Callback.



7
8
9
10
11
12
13
14
15
# File 'lib/ponder/callback.rb', line 7

def initialize(event_type = :channel, match = //, options = {}, 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
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/ponder/callback.rb', line 5

def options
  @options
end

Instance Method Details

#call(event_type, event_data = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ponder/callback.rb', line 17

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