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

Inherits:
Object
  • Object
show all
Defined in:
lib/butler/irc/parser/commands.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.



52
53
54
55
56
57
58
# File 'lib/butler/irc/parser/commands.rb', line 52

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.



47
48
49
# File 'lib/butler/irc/parser/commands.rb', line 47

def mapping
  @mapping
end

#matcherObject (readonly)

Returns the value of attribute matcher.



46
47
48
# File 'lib/butler/irc/parser/commands.rb', line 46

def matcher
  @matcher
end

#processorObject (readonly)

Returns the value of attribute processor.



48
49
50
# File 'lib/butler/irc/parser/commands.rb', line 48

def processor
  @processor
end

#rawObject (readonly)

Returns the value of attribute raw.



44
45
46
# File 'lib/butler/irc/parser/commands.rb', line 44

def raw
  @raw
end

#symbolObject (readonly)

Returns the value of attribute symbol.



45
46
47
# File 'lib/butler/irc/parser/commands.rb', line 45

def symbol
  @symbol
end

Instance Method Details

#create_fields(message) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/butler/irc/parser/commands.rb', line 69

def create_fields(message)
	if @matcher and match = @matcher.match(message.params) then
		@mapping.zip(match.captures) { |name, value|
			message.alter_member(name, value, true)
		}
	end
end

#fields(message) ⇒ Object



64
65
66
67
# File 'lib/butler/irc/parser/commands.rb', line 64

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

#match(message) ⇒ Object



60
61
62
# File 'lib/butler/irc/parser/commands.rb', line 60

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

#process(message, parser) ⇒ Object



77
78
79
# File 'lib/butler/irc/parser/commands.rb', line 77

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