Class: Butler::IRC::Parser::Command
- Inherits:
-
Object
- Object
- Butler::IRC::Parser::Command
- Defined in:
- lib/butler/irc/parser/commands.rb
Overview
Provides parsing information about specific commands.
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #create_fields(message) ⇒ Object
- #fields(message) ⇒ Object
-
#initialize(raw, symbol, matcher = nil, mapping = nil, &processor) ⇒ Command
constructor
See Butler::IRC::COMMANDS for samples on instanciation of Butler::IRC::Command objects.
- #match(message) ⇒ Object
- #process(message, parser) ⇒ Object
Constructor Details
#initialize(raw, symbol, matcher = nil, mapping = nil, &processor) ⇒ Command
See Butler::IRC::COMMANDS for samples on instanciation of Butler::IRC::Command objects.
65 66 67 68 69 70 71 |
# File 'lib/butler/irc/parser/commands.rb', line 65 def initialize(raw, symbol, matcher=nil, mapping=nil, &processor) @raw = raw @symbol = symbol @matcher = matcher @mapping = mapping @processor = processor end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
60 61 62 |
# File 'lib/butler/irc/parser/commands.rb', line 60 def mapping @mapping end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
59 60 61 |
# File 'lib/butler/irc/parser/commands.rb', line 59 def matcher @matcher end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
61 62 63 |
# File 'lib/butler/irc/parser/commands.rb', line 61 def processor @processor end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
57 58 59 |
# File 'lib/butler/irc/parser/commands.rb', line 57 def raw @raw end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
58 59 60 |
# File 'lib/butler/irc/parser/commands.rb', line 58 def symbol @symbol end |
Instance Method Details
#create_fields(message) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/butler/irc/parser/commands.rb', line 82 def create_fields() if @matcher then if match = @matcher.match(.params) then @mapping.zip(match.captures) { |name, value| .alter_member(name, value, true) } else warn "Matching failed in #{symbol} for #{.params.inspect}" end end end |
#fields(message) ⇒ Object
77 78 79 80 |
# File 'lib/butler/irc/parser/commands.rb', line 77 def fields() return nil unless @matcher and match = @matcher.match(.params) Hash.zip(@mapping, match.captures) end |
#match(message) ⇒ Object
73 74 75 |
# File 'lib/butler/irc/parser/commands.rb', line 73 def match() @matcher.match() end |
#process(message, parser) ⇒ Object
94 95 96 |
# File 'lib/butler/irc/parser/commands.rb', line 94 def process(, parser) @processor.call(, parser) if @processor end |