Class: Plugin
- Inherits:
-
Object
- Object
- Plugin
- Defined in:
- lib/fantasy-irc/plugins.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #handle(pattern, &block) ⇒ Object
- #handle!(command, data, args = []) ⇒ Object
- #handles?(command) ⇒ Boolean
-
#initialize(name) ⇒ Plugin
constructor
A new instance of Plugin.
Constructor Details
#initialize(name) ⇒ Plugin
Returns a new instance of Plugin.
35 36 37 38 |
# File 'lib/fantasy-irc/plugins.rb', line 35 def initialize name @name = name @handlers = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/fantasy-irc/plugins.rb', line 33 def name @name end |
Instance Method Details
#handle(pattern, &block) ⇒ Object
40 41 42 |
# File 'lib/fantasy-irc/plugins.rb', line 40 def handle pattern, &block @handlers[pattern] = block end |
#handle!(command, data, args = []) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/fantasy-irc/plugins.rb', line 54 def handle! command, data, args=[] puts "trying to handle #{command} with #{data} and #{args}" @handlers.each do |pattern, block| if command.match(pattern) then puts "#{block} handles #{command}" break block.call data, args end end end |
#handles?(command) ⇒ Boolean
44 45 46 47 48 49 50 51 52 |
# File 'lib/fantasy-irc/plugins.rb', line 44 def handles? command @handlers.keys.each do |pattern| if command.match pattern then return true end end return false end |