Class: Ircp::Message
- Inherits:
-
Object
- Object
- Ircp::Message
- Defined in:
- lib/ircp/message.rb
Constant Summary collapse
- CRLF =
"\r\n"
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#params ⇒ Object
Returns the value of attribute params.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(*args) {|_self| ... } ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #to_irc ⇒ Object (also: #to_s)
Constructor Details
#initialize(*args) {|_self| ... } ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 15 16 |
# File 'lib/ircp/message.rb', line 9 def initialize(*args) = args.last.is_a?(Hash) ? args.pop : {} @raw = [:raw] @prefix = [:prefix] ? Prefix.new([:prefix]) : nil @command = [:command] || args.shift @params = args + Array([:params]) yield self if block_given? end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
7 8 9 |
# File 'lib/ircp/message.rb', line 7 def command @command end |
#params ⇒ Object
Returns the value of attribute params.
7 8 9 |
# File 'lib/ircp/message.rb', line 7 def params @params end |
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/ircp/message.rb', line 7 def prefix @prefix end |
#raw ⇒ Object
Returns the value of attribute raw.
7 8 9 |
# File 'lib/ircp/message.rb', line 7 def raw @raw end |
Instance Method Details
#inspect ⇒ Object
18 19 20 21 22 |
# File 'lib/ircp/message.rb', line 18 def inspect variables = instance_variables.map { |name| "#{name}=#{instance_variable_get(name).inspect}" } variables.unshift "#{self.class}" "<#{variables.join ' '}>" end |
#to_irc ⇒ Object Also known as: to_s
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ircp/message.rb', line 24 def to_irc command = @command.to_s.upcase tokens = [] tokens << ":#{@prefix}" if @prefix tokens << command new_params = @params.dup unless new_params.empty? last = new_params.pop.to_s.dup last.insert 0, ':' if !last.start_with?(':') && last.include?(' ') new_params << last end tokens += new_params msg = tokens.map { |token| token.to_s }.reject { |token| token.empty? }.join(' ') msg << CRLF unless msg.end_with?(CRLF) msg end |