Sha256: 4d337c3433369f006ec977f212a04671dfaf5525478ec2ba26e815a2e2d574eb

Contents?: true

Size: 839 Bytes

Versions: 5

Compression:

Stored size: 839 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]
      yield self if block_given?
    end

    def empty?
      to_s.empty?
    end

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

    def to_irc
      if @servername
        "#{servername}"
      else
        [['', @nick], ['!', @user], ['@', @host]].map do |mark, value|
          "#{mark}#{value}" unless value.to_s.empty?
        end.compact.join('')
      end
    end
    alias_method :to_s, :to_irc
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ircp-1.1.8 lib/ircp/prefix.rb
ircp-1.1.7 lib/ircp/prefix.rb
ircp-1.1.6 lib/ircp/prefix.rb
ircp-1.1.5 lib/ircp/prefix.rb
ircp-1.1.4 lib/ircp/prefix.rb