Class: IIRC::User

Inherits:
Object
  • Object
show all
Defined in:
lib/iirc/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nick: nil, username: nil, realname: nil, host: nil) ⇒ User

Returns a new instance of User.



26
27
28
29
30
31
# File 'lib/iirc/user.rb', line 26

def initialize(nick:nil,username:nil,realname:nil,host:nil)
  self.nick = nick
  self.username = username
  self.realname = realname
  self.host = host
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/iirc/user.rb', line 3

def host
  @host
end

#nickObject

Returns the value of attribute nick.



3
4
5
# File 'lib/iirc/user.rb', line 3

def nick
  @nick
end

#realnameObject Also known as: name, gecos

Returns the value of attribute realname.



3
4
5
# File 'lib/iirc/user.rb', line 3

def realname
  @realname
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/iirc/user.rb', line 3

def username
  @username
end

Class Method Details

.from_sender(str) ⇒ Object Also known as: from_source



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/iirc/user.rb', line 8

def from_sender(str)
  str = str[1..] if str.start_with? ':'

  username, _, host = str.partition("@")
  nick, _, username = username.partition("!")

  return nil if nick.include? '.' # sender is a server, not a user

  nick = nil if nick.empty?
  username = nil if username.empty?
  host = nil if host.empty?

  new(nick: nick, username: username, host: host)
end

Instance Method Details

#===(other) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/iirc/user.rb', line 45

def ===(other)
  if other.respond_to? :nick
    nick and nick.downcase == other.nick.downcase
  elsif other.is_a? String
    if other.include? ' ' or other.include? '.'
      false
    elsif nick
      nick and nick.downcase == User.from_source(other)&.nick&.downcase
    end
  else
    false
  end
end

#to_prefixObject



41
42
43
# File 'lib/iirc/user.rb', line 41

def to_prefix
  ":#{self}"
end

#to_sObject



33
34
35
36
37
38
39
# File 'lib/iirc/user.rb', line 33

def to_s
  "#{nick}".tap do |s|
    if username and host
      s << "!#{username}@#{host}"
    end
  end
end