Class: WebSocketChatServer::ChatUser
- Inherits:
-
Object
- Object
- WebSocketChatServer::ChatUser
- Defined in:
- lib/web_socket_chat_server.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #==(object) ⇒ Object
- #admin? ⇒ Boolean
-
#initialize(args = {}) ⇒ ChatUser
constructor
A new instance of ChatUser.
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ChatUser
Returns a new instance of ChatUser.
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
#connection ⇒ Object
Returns the value of attribute connection.
392 393 394 |
# File 'lib/web_socket_chat_server.rb', line 392 def connection @connection end |
#ip ⇒ Object
Returns the value of attribute ip.
392 393 394 |
# File 'lib/web_socket_chat_server.rb', line 392 def ip @ip end |
#password ⇒ Object
Returns the value of attribute password.
392 393 394 |
# File 'lib/web_socket_chat_server.rb', line 392 def password @password end |
#username ⇒ Object
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
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( = {}) {"user" => @username}.to_json end |