Class: Vetinari::UserContainer

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/vetinari/user_container.rb

Overview

The UserList class holds information about users a Thaum is able to see in channels.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUserContainer

Returns a new instance of UserContainer.



11
12
13
# File 'lib/vetinari/user_container.rb', line 11

def initialize
  @users = Set.new
end

Instance Attribute Details

#usersObject (readonly)

Returns the value of attribute users.



7
8
9
# File 'lib/vetinari/user_container.rb', line 7

def users
  @users
end

Instance Method Details

#[](user_or_nick) ⇒ Object

Find a User given the nick.



25
26
27
28
29
30
31
32
33
34
# File 'lib/vetinari/user_container.rb', line 25

def [](user_or_nick)
  case user_or_nick
  when User
    user_or_nick if @users.include?(user_or_nick)
  when String
    @users.find do |u|
      u.nick.downcase == user_or_nick.downcase
    end
  end
end

#add(user) ⇒ Object



15
16
17
# File 'lib/vetinari/user_container.rb', line 15

def add(user)
  @users << user
end

#clearObject



40
41
42
# File 'lib/vetinari/user_container.rb', line 40

def clear
  @users.clear
end

#has_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/vetinari/user_container.rb', line 36

def has_user?(user)
  self[user] ? true : false
end

#kill_zombie_users(users) ⇒ Object

Removes all users from the UserContainer that don’t share channels with the Bot.



46
47
48
49
50
# File 'lib/vetinari/user_container.rb', line 46

def kill_zombie_users(users)
  (@users - users).each do |user|
    @users.delete(user) unless user.bot?
  end
end

#remove(user) ⇒ Object

TODO



20
21
22
# File 'lib/vetinari/user_container.rb', line 20

def remove(user)
  @users.delete(user)
end