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.



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

#mappingObject (readonly)

Returns the value of attribute mapping.



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

def mapping
  @mapping
end

#matcherObject (readonly)

Returns the value of attribute matcher.



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

def matcher
  @matcher
end

#processorObject (readonly)

Returns the value of attribute processor.



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

def processor
  @processor
end

#rawObject (readonly)

Returns the value of attribute raw.



57
58
59
# File 'lib/butler/irc/parser/commands.rb', line 57

def raw
  @raw
end

#symbolObject (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(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



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

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

#match(message) ⇒ Object



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

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

#process(message, parser) ⇒ Object



94
95
96
# File 'lib/butler/irc/parser/commands.rb', line 94

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