Class: Butler::IRC::Parser::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/butler/irc/parser/command.rb

Overview

Provides parsing information about specific commands.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#mappingObject (readonly)

Returns the value of attribute mapping.



22
23
24
# File 'lib/butler/irc/parser/command.rb', line 22

def mapping
  @mapping
end

#matcherObject (readonly)

Returns the value of attribute matcher.



21
22
23
# File 'lib/butler/irc/parser/command.rb', line 21

def matcher
  @matcher
end

#processorObject (readonly)

Returns the value of attribute processor.



23
24
25
# File 'lib/butler/irc/parser/command.rb', line 23

def processor
  @processor
end

#rawObject (readonly)

Returns the value of attribute raw.



19
20
21
# File 'lib/butler/irc/parser/command.rb', line 19

def raw
  @raw
end

#symbolObject (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(message)
	if @matcher then
		if match = @matcher.match(message.params) then
			@mapping.zip(match.captures) { |name, value|
				message.alter_member(name, value, true)
			}
		else
			warn "Matching failed in #{symbol} for #{message.params.inspect}"
		end
	end
end

#fields(message) ⇒ Object



39
40
41
42
# File 'lib/butler/irc/parser/command.rb', line 39

def fields(message)
	return nil unless @matcher and match = @matcher.match(message.params)
	Hash.zip(@mapping, match.captures)
end

#match(message) ⇒ Object



35
36
37
# File 'lib/butler/irc/parser/command.rb', line 35

def match(message)
	@matcher.match(message)
end

#process(message, parser) ⇒ Object



56
57
58
# File 'lib/butler/irc/parser/command.rb', line 56

def process(message, parser)
	@processor.call(message, parser) if @processor
end