Class: IRC::Callback
- Inherits:
-
Object
- Object
- IRC::Callback
- Defined in:
- lib/irc/callback.rb
Class Attribute Summary collapse
-
.callbacks ⇒ Object
Returns the value of attribute callbacks.
-
.filters ⇒ Object
Returns the value of attribute filters.
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#regex ⇒ Object
Returns the value of attribute regex.
Class Method Summary collapse
Instance Method Summary collapse
- #call!(message) ⇒ Object
-
#initialize(action, regex = nil, factory = nil, &block) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(action, regex = nil, factory = nil, &block) ⇒ Callback
Returns a new instance of Callback.
5 6 7 8 9 10 |
# File 'lib/irc/callback.rb', line 5 def initialize action, regex = nil, factory = nil, &block @action = action @regex = regex || // @block = block @factory = factory end |
Class Attribute Details
.callbacks ⇒ Object
Returns the value of attribute callbacks.
32 33 34 |
# File 'lib/irc/callback.rb', line 32 def callbacks @callbacks end |
.filters ⇒ Object
Returns the value of attribute filters.
32 33 34 |
# File 'lib/irc/callback.rb', line 32 def filters @filters end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
3 4 5 |
# File 'lib/irc/callback.rb', line 3 def action @action end |
#regex ⇒ Object
Returns the value of attribute regex.
3 4 5 |
# File 'lib/irc/callback.rb', line 3 def regex @regex end |
Class Method Details
.add(action, *args, &block) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/irc/callback.rb', line 40 def add action, *args, &block callback = new(action, *args, &block) callbacks[action] << callback callbacks[:all] << callback end |
.clear! ⇒ Object
50 51 52 53 |
# File 'lib/irc/callback.rb', line 50 def clear! @callbacks = nil callbacks end |
.handle(message) ⇒ Object
34 35 36 37 38 |
# File 'lib/irc/callback.rb', line 34 def handle callbacks[.action].each do |callback| callback.call! end end |
Instance Method Details
#call!(message) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/irc/callback.rb', line 12 def call! match = regex.match(.content) return if !match (class << ; self; end).send :attr_accessor, *@regex.names match.names.each do |name| .instance_variable_set("@#{name}", match[name]) end Job.schedule do if @factory @factory.new().instance_eval(&@block) else @block.call(, match) end end end |