Class: IRC::Client::Users

Inherits:
ThreadSafeHash show all
Defined in:
lib/failirc/client/users.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, *args) ⇒ Users

Returns a new instance of Users.



31
32
33
34
35
# File 'lib/failirc/client/users.rb', line 31

def initialize (channel, *args)
    @channel = channel

    super(*args)
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



29
30
31
# File 'lib/failirc/client/users.rb', line 29

def channel
  @channel
end

Instance Method Details

#[](user) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/failirc/client/users.rb', line 47

def [] (user)
    if user.is_a?(Client) || user.is_a?(User)
        user = user.nick
    end

    __get(user)
end

#[]=(user, value) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/failirc/client/users.rb', line 57

def []= (user, value)
    if user.is_a?(Client) || user.is_a?(User)
        user = user.nick
    end

    __set(user, value)
end

#__deleteObject



65
# File 'lib/failirc/client/users.rb', line 65

alias __delete delete

#__getObject



45
# File 'lib/failirc/client/users.rb', line 45

alias __get []

#__setObject



55
# File 'lib/failirc/client/users.rb', line 55

alias __set []=

#add(user) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/failirc/client/users.rb', line 87

def add (user)
    if user.is_a?(Client)
        self[user.nick] = User.new(user, @channel)
    elsif user.is_a?(User)
        self[user.nick] = user
    else
        raise 'You can only add Client or User.'
    end
end

#clientObject



37
38
39
# File 'lib/failirc/client/users.rb', line 37

def client
    @channel.client
end

#delete(key) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/failirc/client/users.rb', line 67

def delete (key)
    if key.is_a?(User) || key.is_a?(Client)
        key = key.nick
    end

    key = key.downcase

    user = self[key]

    if user
        __delete(key)

        if channel.empty?
            server.channels.delete(channel)
        end
    end

    return user
end

#serverObject



41
42
43
# File 'lib/failirc/client/users.rb', line 41

def server
    @channel.server
end