Class: Ircp::Prefix

Inherits:
Object
  • Object
show all
Defined in:
lib/ircp/prefix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Prefix

Returns a new instance of Prefix.

Yields:

  • (_self)

Yield Parameters:

  • _self (Ircp::Prefix)

    the object that the method was called on



5
6
7
8
9
10
11
12
# File 'lib/ircp/prefix.rb', line 5

def initialize(options = {})
  @raw = options[:raw]
  @servername = options[:servername]
  @nick = options[:nick]
  @user = options[:user]
  @host = options[:host]
  yield self if block_given?
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/ircp/prefix.rb', line 3

def host
  @host
end

#nickObject

Returns the value of attribute nick.



3
4
5
# File 'lib/ircp/prefix.rb', line 3

def nick
  @nick
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/ircp/prefix.rb', line 3

def raw
  @raw
end

#servernameObject

Returns the value of attribute servername.



3
4
5
# File 'lib/ircp/prefix.rb', line 3

def servername
  @servername
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'lib/ircp/prefix.rb', line 3

def user
  @user
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ircp/prefix.rb', line 14

def empty?
  to_s.empty?
end

#inspectObject



18
19
20
21
22
# File 'lib/ircp/prefix.rb', line 18

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

#to_ircObject Also known as: to_s



24
25
26
27
28
29
30
31
32
# File 'lib/ircp/prefix.rb', line 24

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