Class: Relayer::IRC::User

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

Constant Summary collapse

IRC_HOSTMASK_REGEX =
/^([^\!@]+)(\!([^\!@]+))(@(.+))$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostmask) ⇒ User

Returns a new instance of User.



31
32
33
34
# File 'lib/relayer/irc/user.rb', line 31

def initialize(hostmask)
  @hostmask = hostmask
  parse_hostmask!
end

Instance Attribute Details

#hostmaskObject

Returns the value of attribute hostmask.



5
6
7
# File 'lib/relayer/irc/user.rb', line 5

def hostmask
  @hostmask
end

#hostnameObject

Returns the value of attribute hostname.



5
6
7
# File 'lib/relayer/irc/user.rb', line 5

def hostname
  @hostname
end

#identObject

Returns the value of attribute ident.



5
6
7
# File 'lib/relayer/irc/user.rb', line 5

def ident
  @ident
end

#nickObject

Returns the value of attribute nick.



5
6
7
# File 'lib/relayer/irc/user.rb', line 5

def nick
  @nick
end

Class Method Details

.is_user?(hostmask) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/relayer/irc/user.rb', line 7

def self.is_user?(hostmask)
  not IRC_HOSTMASK_REGEX.match(hostmask).nil?
end

.parse_hostmask(hostmask) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/relayer/irc/user.rb', line 15

def self.parse_hostmask(hostmask)
  match = IRC_HOSTMASK_REGEX.match hostmask
  return if match.nil?
  
  raw, nick, ident_tmp, ident, hostname_tmp, hostname = match.to_a
  return :nick => nick, :ident => ident, :hostname => hostname
end

Instance Method Details

#parse_hostmask!Object



23
24
25
26
27
28
29
# File 'lib/relayer/irc/user.rb', line 23

def parse_hostmask!
  parts = User.parse_hostmask @hostmask
  
  @nick = parts[:nick]
  @ident = parts[:ident]
  @hostname = parts[:hostname]
end

#to_sObject



11
12
13
# File 'lib/relayer/irc/user.rb', line 11

def to_s
  @nick
end