Sha256: d7a54c46e43350de42992adf914c572c6b3c519620f036278826ed53ef4b7a5e

Contents?: true

Size: 796 Bytes

Versions: 1

Compression:

Stored size: 796 Bytes

Contents

require 'ircp/prefix'

module Ircp
  class Message
    attr_accessor :raw, :prefix, :command, :params

    def initialize(*args)
      options = args.last.is_a?(Hash) ? args.pop : {}
      @raw = options[:raw]
      @prefix = options[:prefix] ? Prefix.new(options[:prefix]) : nil
      @command = options[:command]
      @params = args + Array(options[:params])
    end

    def inspect
      variables = instance_variables.map { |name| "#{name.inspect}=#{instance_variable_get(name).inspect}" }
      variables.unshift "#{self.class}"
      "<#{variables.join ' '}>"
    end

    def to_irc
      msg = [@prefix, @command, *@params].map { |v| v.to_s }.reject { |v| v.empty? }.join(' ')
      msg << "\r\n" unless msg.end_with?("\r\n")
      msg
    end
    alias_method :to_s, :to_irc
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ircp-1.1.2 lib/ircp/message.rb