Class: SugiliteIRC::Message
- Inherits:
-
Object
- Object
- SugiliteIRC::Message
- Defined in:
- lib/sugiliteIRC.rb
Overview
Parses standard IRC messages
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Message commands (i.e. PING and PRIVMSG).
-
#parameters ⇒ Object
readonly
Message parameters.
-
#prefix ⇒ Object
readonly
Message prefix.
-
#raw ⇒ Object
readonly
Raw message.
-
#tags ⇒ Object
readonly
Message tags.
Instance Method Summary collapse
-
#channel ⇒ Object
Gets Channel from irc data.
-
#initialize(data) ⇒ Message
constructor
Initalizes message.
-
#message ⇒ Object
Gets message contents as a string.
-
#sender ⇒ Object
Gets the sender.
-
#to_s ⇒ Object
Dumps from JSON object to String.
Constructor Details
#initialize(data) ⇒ Message
Initalizes message
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sugiliteIRC.rb', line 43 def initialize(data) @raw = data = {} @parameters = [] @prefix = nil data = data.split(' ') data2 = data.shift if data2[0] == '@' data2[1..-1].split(';').each { |r_tag| s_tag = r_tag.split('=', 2); [s_tag[0]] = s_tag[1] } data2 = data.shift end if data2[0] == ':' @prefix = Prefix.new(data2) data2 = data.shift end @command = data2 loop do if data[0].nil? break elsif data[0][0] == ':' @parameters.push(data.join(' ')[1..-1]) break elsif data.length == 1 @parameters.push(data[0]) break else @parameters.push(data.shift) end end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Message commands (i.e. PING and PRIVMSG)
41 42 43 |
# File 'lib/sugiliteIRC.rb', line 41 def command @command end |
#parameters ⇒ Object (readonly)
Message parameters
37 38 39 |
# File 'lib/sugiliteIRC.rb', line 37 def parameters @parameters end |
#prefix ⇒ Object (readonly)
Message prefix
39 40 41 |
# File 'lib/sugiliteIRC.rb', line 39 def prefix @prefix end |
#raw ⇒ Object (readonly)
Raw message
33 34 35 |
# File 'lib/sugiliteIRC.rb', line 33 def raw @raw end |
#tags ⇒ Object (readonly)
Message tags
35 36 37 |
# File 'lib/sugiliteIRC.rb', line 35 def end |
Instance Method Details
#channel ⇒ Object
Gets Channel from irc data.
80 81 82 83 84 85 86 87 |
# File 'lib/sugiliteIRC.rb', line 80 def channel case @command when 'PRIVMSG', 'NOTICE', 'HOSTTARGET', 'ROOMSTATE', 'USERNOTICE', 'USERSTATE' @parameters[0] else nil end end |
#message ⇒ Object
Gets message contents as a string.
100 101 102 103 104 105 106 107 |
# File 'lib/sugiliteIRC.rb', line 100 def case @command when 'PRIVMSG', 'NOTICE' @parameters[1] else nil end end |
#sender ⇒ Object
Gets the sender.
90 91 92 93 94 95 96 97 |
# File 'lib/sugiliteIRC.rb', line 90 def sender case @command when 'PRIVMSG', 'NOTICE' @prefix.realname else nil end end |
#to_s ⇒ Object
Dumps from JSON object to String.
75 76 77 |
# File 'lib/sugiliteIRC.rb', line 75 def to_s Oj.dump self, indent: 2 end |