Class: Whatup::Server::Client
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Whatup::Server::Client
- Defined in:
- lib/whatup/server/models/client.rb
Instance Method Summary collapse
- #broadcast(msg) ⇒ Object
- #chatting? ⇒ Boolean
- #composing_dm? ⇒ Boolean
- #exit! ⇒ Object
- #gets ⇒ Object
- #input! ⇒ Object
- #leave_room! ⇒ Object
- #puts(msg) ⇒ Object
- #status ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#broadcast(msg) ⇒ Object
44 45 46 |
# File 'lib/whatup/server/models/client.rb', line 44 def broadcast msg room.broadcast(except: self) { "#{name}> #{msg}" } end |
#chatting? ⇒ Boolean
32 33 34 |
# File 'lib/whatup/server/models/client.rb', line 32 def chatting? !room_id.nil? end |
#composing_dm? ⇒ Boolean
36 37 38 |
# File 'lib/whatup/server/models/client.rb', line 36 def composing_dm? !composing_dm.nil? end |
#exit! ⇒ Object
52 53 54 55 56 57 |
# File 'lib/whatup/server/models/client.rb', line 52 def exit! puts 'END' socket.close @deleted = true destroy! end |
#gets ⇒ Object
23 24 25 |
# File 'lib/whatup/server/models/client.rb', line 23 def gets socket&.gets end |
#input! ⇒ Object
27 28 29 30 |
# File 'lib/whatup/server/models/client.rb', line 27 def input! loop while (msg = gets).blank? msg.chomp end |
#leave_room! ⇒ Object
48 49 50 |
# File 'lib/whatup/server/models/client.rb', line 48 def leave_room! room.drop_client! self end |
#puts(msg) ⇒ Object
19 20 21 |
# File 'lib/whatup/server/models/client.rb', line 19 def puts msg socket&.puts(msg) end |
#status ⇒ Object
40 41 42 |
# File 'lib/whatup/server/models/client.rb', line 40 def status "#{name}#{chatting? ? " (#{room.name})" : ''}" end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/whatup/server/models/client.rb', line 59 def to_s name end |