Class: IRConnect::Command

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

Overview

represents an IRC Command received from the server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_string) ⇒ Command

IRC message format: :<prefix> <command> <params> :<trailing> info on parsing commands: goo.gl/N3YGLq



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/command.rb', line 10

def initialize(command_string)
  fail 'Bad IRC command format' unless command_string =~ /
      \A (?::([^\040]+)\040)?  # prefix
      ([A-Za-z]+|\d{3})        # command
      ((?:\040[^:][^\040]+)*)  # all but the last param
      (?:\040:?(.*))?          # last param
      \Z
    /x
  @prefix, @command = Regexp.last_match(1), Regexp.last_match(2)
  parse_params(Regexp.last_match(3), Regexp.last_match(4))
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/command.rb', line 4

def command
  @command
end

#last_paramObject (readonly)

Returns the value of attribute last_param.



4
5
6
# File 'lib/command.rb', line 4

def last_param
  @last_param
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/command.rb', line 4

def params
  @params
end

#prefixObject (readonly)

Returns the value of attribute prefix.



4
5
6
# File 'lib/command.rb', line 4

def prefix
  @prefix
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
# File 'lib/command.rb', line 22

def ==(other)
  prefix == other.prefix &&
    command == other.command &&
    params == other.params
end