Class: Butler::IRC::Parser::Command
- Inherits:
-
Object
- Object
- Butler::IRC::Parser::Command
- Defined in:
- lib/butler/irc/parser/command.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.
27 28 29 30 31 32 33 |
# File 'lib/butler/irc/parser/command.rb', line 27 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.
22 23 24 |
# File 'lib/butler/irc/parser/command.rb', line 22 def mapping @mapping end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
21 22 23 |
# File 'lib/butler/irc/parser/command.rb', line 21 def matcher @matcher end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
23 24 25 |
# File 'lib/butler/irc/parser/command.rb', line 23 def processor @processor end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
19 20 21 |
# File 'lib/butler/irc/parser/command.rb', line 19 def raw @raw end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
20 21 22 |
# File 'lib/butler/irc/parser/command.rb', line 20 def symbol @symbol end |
Instance Method Details
#create_fields(message) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/butler/irc/parser/command.rb', line 44 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
39 40 41 42 |
# File 'lib/butler/irc/parser/command.rb', line 39 def fields() return nil unless @matcher and match = @matcher.match(.params) Hash.zip(@mapping, match.captures) end |
#match(message) ⇒ Object
35 36 37 |
# File 'lib/butler/irc/parser/command.rb', line 35 def match() @matcher.match() end |
#process(message, parser) ⇒ Object
56 57 58 |
# File 'lib/butler/irc/parser/command.rb', line 56 def process(, parser) @processor.call(, parser) if @processor end |