Sha256: c8312aea81f03add5638c8224ccfff03d3eea656686debdc16776428f8827f69

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

module Ircp
  class Prefix
    attr_accessor :raw, :servername, :nick, :user, :host

    def initialize(options = {})
      @raw = options[:raw]
      @servername = options[:servername]
      @nick = options[:nick]
      @user = options[:user]
      @host = options[:host]
    end

    def empty?
      to_s.empty?
    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
      if @raw.nil? || @raw.empty?
        if @servername
          ":#{servername}"
        else
          tokens = []
          tokens << ":#{@nick}" unless @nick.nil?
          tokens << "!#{@user}" unless @user.nil?
          tokens << "@#{@host}" unless @host.nil?
          tokens.join ''
        end
      else
        @raw.to_s
      end
    end
    alias_method :to_s, :to_irc
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ircp-1.1.1 lib/ircp/prefix.rb