Sha256: 7a633e3107eb46697c797b8fb552da60cd1c38ee3a7741961d68b5e8a36ef3f3

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

class Net::IRC::Message::ModeParser

	def initialize(require_arg, definition)
		@require_arg = require_arg.map {|i| i.to_sym }
		@definition  = definition
	end

	def parse(arg)
		params = arg.kind_of?(Net::IRC::Message) ? arg.to_a : arg.split(/\s+/)

		ret =  {
			:positive => [],
			:negative => [],
		}

		current = nil, arg_pos = 0
		params[1].each_byte do |c|
			sym = c.chr.to_sym
			case sym
			when :+
				current = ret[:positive]
			when :-
				current = ret[:negative]
			else
				case
				when @require_arg.include?(sym)
					current << [sym, params[arg_pos + 2]]
					arg_pos += 1
				when @definition.key?(sym)
					current << [sym, nil]
				else
					# fallback, should raise exception
					# but not for convenience
					current << [sym, nil]
				end
			end
		end

		ret
	end

	autoload :RFC1459,  "net/irc/message/modeparser/rfc1459"
	autoload :Hyperion, "net/irc/message/modeparser/hyperion"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-irc-0.0.4 lib/net/irc/message/modeparser.rb