Class: IRC::Message

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

Constant Summary collapse

REGEX =
/^
  (:
    (?<prefix>
      (
        (?<servername>(?<nick>[a-z][a-z0-9_\-\[\]\\`\^\{\}\.\|]*))
      )
      (!(?<user>[a-z0-9~\.]+))?
      (@(?<host>[a-z0-9\.]+))?
    )
    [\ ]+
  )?
  (?<command>[a-z]+|[0-9]{3})
  (?<params>
    (\ +(?<middle>[^:\r\n\ ][^\r\n\ ]*))*
    (\ *:(?<trailing>.+))?
  )
  \r\n$
/xi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_string, connection) ⇒ Message

Returns a new instance of Message.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/irc/message.rb', line 26

def initialize message_string, connection
  @raw = message_string

  @connection = connection
  @match = REGEX.match(message_string) || {}

  REGEX.names.each do |name|
    instance_variable_set("@#{name}", @match[name])
  end

end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



23
24
25
# File 'lib/irc/message.rb', line 23

def connection
  @connection
end

#rawObject (readonly)

Returns the value of attribute raw.



22
23
24
# File 'lib/irc/message.rb', line 22

def raw
  @raw
end

Instance Method Details

#actionObject



38
39
40
# File 'lib/irc/message.rb', line 38

def action
  @action ||= (command || '').downcase.intern
end

#contentObject



42
43
44
# File 'lib/irc/message.rb', line 42

def content
  @content ||= trailing || middle
end