Class: WebSocketChatServer::ChatUser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ChatUser

Returns a new instance of ChatUser.

Raises:

  • (RuntimeError)


393
394
395
396
397
398
399
400
401
402
# File 'lib/web_socket_chat_server.rb', line 393

def initialize(args = {})
	raise RuntimeError, "The username is not given" unless args.has_key?(:username)
	raise RuntimeError, "The password is not given" unless args.has_key?(:password)

	@connection = nil
	@connection = args[:connection] if args.has_key?(:connection)
	@ip = args[:ip] if args.has_key?(:ip)
	@username = args[:username]
	@password = args[:password]
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



392
393
394
# File 'lib/web_socket_chat_server.rb', line 392

def connection
  @connection
end

#ipObject

Returns the value of attribute ip.



392
393
394
# File 'lib/web_socket_chat_server.rb', line 392

def ip
  @ip
end

#passwordObject

Returns the value of attribute password.



392
393
394
# File 'lib/web_socket_chat_server.rb', line 392

def password
  @password
end

#usernameObject

Returns the value of attribute username.



392
393
394
# File 'lib/web_socket_chat_server.rb', line 392

def username
  @username
end

Instance Method Details

#==(object) ⇒ Object



408
409
410
411
# File 'lib/web_socket_chat_server.rb', line 408

def ==(object)
	return false unless object.class == ChatUser
	return username == object.username
end

#admin?Boolean

Returns:

  • (Boolean)


404
405
406
# File 'lib/web_socket_chat_server.rb', line 404

def admin?()
	@is_admin
end

#to_json(options = {}) ⇒ Object



413
414
415
# File 'lib/web_socket_chat_server.rb', line 413

def to_json(options = {})
	{"user" => @username}.to_json
end