Class: IRC::Message

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

Constant Summary collapse

REGEX =
/^
  (:
    (?<prefix>
      (
        (?<servername>(?<nick>[a-z#{special_characters}][a-z0-9#{special_characters}]*))
      )
      (!(?<user>[a-z0-9~\.]+))?
      (@(?<host>[a-z0-9\.\-_]{1,255}))?
    )
    [\ ]+
  )?
  (?<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 = nil) ⇒ Message

Returns a new instance of Message.



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

def initialize message_string, connection = nil
  @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.



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

def connection
  @connection
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

Instance Method Details

#actionObject



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

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

#contentObject



47
48
49
# File 'lib/irc/message.rb', line 47

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

#targetObject



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

def target
  middle
end