Class: Net::IRC::Message
- Inherits:
-
Object
- Object
- Net::IRC::Message
- Defined in:
- lib/net/irc.rb
Direct Known Subclasses
Join, Mode, Nick, Notice, Part, Pass, Ping, Pong, Privmsg, Quit, Reply, User
Defined Under Namespace
Classes: Prefix
Constant Summary collapse
- COMMAND_MAPS =
%w(rfc1459 rfc2812 isupport hybrid ircu)
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Message
constructor
A new instance of Message.
- #prefix? ⇒ Boolean
- #to_s ⇒ Object
- #write(socket) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Message
Returns a new instance of Message.
152 153 154 155 156 157 158 159 160 |
# File 'lib/net/irc.rb', line 152 def initialize(*args) raise ArgumentError, "wrong number of arguments (#{args.size} for 2)" if args.size < 2 # puts ">>>>> args=#{args.inspect}" @prefix, @command, *parameters = args # puts ">>>>> @prefix=#{@prefix.inspect}, command=#{@command.inspect}, parameters=#{parameters.inspect}" @parameters = Array(parameters) end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
148 149 150 |
# File 'lib/net/irc.rb', line 148 def command @command end |
#parameters ⇒ Object
Returns the value of attribute parameters.
148 149 150 |
# File 'lib/net/irc.rb', line 148 def parameters @parameters end |
#prefix ⇒ Object
Returns the value of attribute prefix.
147 148 149 |
# File 'lib/net/irc.rb', line 147 def prefix @prefix end |
Class Method Details
.command_for_number(number) ⇒ Object
252 253 254 255 |
# File 'lib/net/irc.rb', line 252 def command_for_number(number) @command_map ||= COMMAND_MAPS.inject({}) { |merged,map| merged.merge!(YAML.load_file("#{File.dirname(__FILE__)}/#{map}.yml")) } @command_map[number] end |
.parse(line) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/net/irc.rb', line 225 def parse(line) scanner = StringScanner.new(line) prefix = scanner.scan(/:([^ ]+) /) && scanner[1] command = scanner.scan(/[[:alpha:]]+|\d{3}/) params = [] 14.times do break if ! scanner.scan(/ ([^ :][^ ]*)/) params << scanner[1] end params << scanner[1] if scanner.scan(/ :(.+)/) = nil command_name = command.to_i > 0 ? command_for_number(command.to_i) : command if command_name = "#{command_name.downcase.split('_').collect { |w| w.capitalize }.join}" if Net::IRC.const_defined?() = Net::IRC.const_get() = .new(*params) .prefix = prefix end end ||= Message.new(prefix, command_name || command, *params) end |
Instance Method Details
#prefix? ⇒ Boolean
197 198 199 |
# File 'lib/net/irc.rb', line 197 def prefix? @prefix end |
#to_s ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/net/irc.rb', line 201 def to_s # puts ">>>>> prefix=#{prefix.inspect}, command=#{command.inspect}, parameters=#{parameters.inspect}" str = prefix ? ":#{prefix} " : "" str << command if ! parameters.empty? parameters[0..-2].each do |param| str << " #{param}" end if parameters.last =~ /^:| / str << " :#{parameters.last}" else str << " #{parameters.last}" end end str end |