Class: IRCd::User

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

Constant Summary collapse

@@identifier =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nick, user, host, real, socket, mode = 0) ⇒ User

Returns a new instance of User.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rupircd/user.rb', line 24

def initialize(nick, user, host, real, socket, mode=0)
  @nick = nick
  @user = user
  @host = host
  @real = real
  @identifier = (@@identifier += 1)
  @away = ""
  @invisible = false
  @wallop = false
  @restriction = false
  @operator = false
  @local_operator = false
  @s = false
  @socket = socket
  @joined_channels = []
end

Instance Attribute Details

#awayObject

Returns the value of attribute away.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def away
  @away
end

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/rupircd/user.rb', line 16

def host
  @host
end

#identifierObject (readonly)

Returns the value of attribute identifier.



16
17
18
# File 'lib/rupircd/user.rb', line 16

def identifier
  @identifier
end

#invisibleObject

Returns the value of attribute invisible.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def invisible
  @invisible
end

#joined_channelsObject

Returns the value of attribute joined_channels.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def joined_channels
  @joined_channels
end

#local_operatorObject

Returns the value of attribute local_operator.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def local_operator
  @local_operator
end

#nickObject

Returns the value of attribute nick.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def nick
  @nick
end

#operatorObject

Returns the value of attribute operator.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def operator
  @operator
end

#realObject

Returns the value of attribute real.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def real
  @real
end

#restrictionObject

Returns the value of attribute restriction.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def restriction
  @restriction
end

#sObject

Returns the value of attribute s.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def s
  @s
end

#socketObject (readonly)

Returns the value of attribute socket.



16
17
18
# File 'lib/rupircd/user.rb', line 16

def socket
  @socket
end

#userObject (readonly)

Returns the value of attribute user.



16
17
18
# File 'lib/rupircd/user.rb', line 16

def user
  @user
end

#wallopObject

Returns the value of attribute wallop.



17
18
19
# File 'lib/rupircd/user.rb', line 17

def wallop
  @wallop
end

Instance Method Details

#==(other) ⇒ Object



98
99
100
# File 'lib/rupircd/user.rb', line 98

def ==(other)
  @identifier == other.identifier
end

#away?Boolean

Returns:

  • (Boolean)


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

def away?
  !@away.empty?
end

#get_mode_flagsObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/rupircd/user.rb', line 87

def get_mode_flags
  mode = ""
  mode << "i" if @invisible
  mode << "w" if @wallop
  mode << "r" if @restriction
  mode << "o" if @operator
  mode << "O" if @local_operator
  mode << "s" if @s
  mode
end

#set_flags(*flags) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rupircd/user.rb', line 49

def set_flags(*flags)
  rls = []
  flags.each{|flg|
    fl = flg[0,1]
    toggle = flg[0] == ?+
    flg[1..-1].split("").each{|md|
      case md
      when "i"
        @invisible = toggle
        fl << "i"
      when "w"
        @wallop = toggle
        fl << "w"
      when"r"
        if toggle
          @restriction = true
          fl << "r"
        end
      when "o"
        unless toggle
          @operator = false
          fl << "o"
        end
      when "O"
        unless toggle
          @local_operator = false
          fl << "O"
        end
      when "s"
        @s = toggle
        fl << "s"
      end
    }
    rls << fl
  }
  rls
end

#to_aObject



45
46
47
# File 'lib/rupircd/user.rb', line 45

def to_a
  [@nick, @user, @host, "*", @real]
end

#to_sObject



20
21
22
# File 'lib/rupircd/user.rb', line 20

def to_s
  @nick + "!" + @user + "@" + @host
end