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)


406
407
408
409
410
411
412
413
414
415
# File 'lib/web_socket_chat_server.rb', line 406

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.



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

def connection
  @connection
end

#ipObject

Returns the value of attribute ip.



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

def ip
  @ip
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#==(object) ⇒ Object



421
422
423
424
# File 'lib/web_socket_chat_server.rb', line 421

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

#admin?Boolean

Returns:

  • (Boolean)


417
418
419
# File 'lib/web_socket_chat_server.rb', line 417

def admin?()
  @is_admin
end

#to_json(options = {}) ⇒ Object



426
427
428
# File 'lib/web_socket_chat_server.rb', line 426

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