Class: Raibo::IrcMessage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ IrcMessage

Returns a new instance of IrcMessage.



13
14
15
# File 'lib/raibo/message.rb', line 13

def initialize(line)
  @prefix, @type, @middle, @trailing = parse_line(line)
end

Instance Attribute Details

#middleObject (readonly)

Returns the value of attribute middle.



11
12
13
# File 'lib/raibo/message.rb', line 11

def middle
  @middle
end

#prefixObject (readonly)

Returns the value of attribute prefix.



11
12
13
# File 'lib/raibo/message.rb', line 11

def prefix
  @prefix
end

#trailingObject (readonly)

Returns the value of attribute trailing.



11
12
13
# File 'lib/raibo/message.rb', line 11

def trailing
  @trailing
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/raibo/message.rb', line 11

def type
  @type
end

Instance Method Details

#bodyObject



42
43
44
45
46
47
48
49
# File 'lib/raibo/message.rb', line 42

def body
  case kind
  when :message
    trailing
  when :emote
    trailing[/\001ACTION ([^\001]*)/, 1]
  end
end

#fromObject



32
33
34
# File 'lib/raibo/message.rb', line 32

def from
  prefix[/^([^!@ ]*)/, 1]
end

#kindObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/raibo/message.rb', line 17

def kind
  case type
  when 'PRIVMSG'
    if trailing =~ /^\001ACTION/
      :emote
    else
      :message
    end
  when 'JOIN'
    :join
  when 'PART'
    :part
  end
end

#toObject



36
37
38
39
40
# File 'lib/raibo/message.rb', line 36

def to
  if [:message, :emote].include?(kind)
    middle.first
  end
end