Class: MadChatter::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/mad_chatter/users.rb

Instance Method Summary collapse

Constructor Details

#initializeUsers

Returns a new instance of Users.



4
5
6
# File 'lib/mad_chatter/users.rb', line 4

def initialize
  @users = {}
end

Instance Method Details

#add(token, username = nil) ⇒ Object



8
9
10
# File 'lib/mad_chatter/users.rb', line 8

def add(token, username = nil)
  @users[token] = username
end

#currentObject



24
25
26
# File 'lib/mad_chatter/users.rb', line 24

def current
  @users.values
end

#find_username_by_token(token) ⇒ Object



20
21
22
# File 'lib/mad_chatter/users.rb', line 20

def find_username_by_token(token)
  @users[token]
end

#remove(token) ⇒ Object



16
17
18
# File 'lib/mad_chatter/users.rb', line 16

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

#to_jsonObject



32
33
34
35
36
37
# File 'lib/mad_chatter/users.rb', line 32

def to_json
  JSON.generate({
    type: 'users',
    json: current,
  })
end

#token_exists?(token) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mad_chatter/users.rb', line 28

def token_exists?(token)
  @users[token].exists?
end

#update(token, username) ⇒ Object



12
13
14
# File 'lib/mad_chatter/users.rb', line 12

def update(token, username)
  @users[token] = username
end