Class: Whatup::Server::Client

Inherits:
ApplicationRecord show all
Defined in:
lib/whatup/server/models/client.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/whatup/server/models/client.rb', line 32

def chatting?
  !room_id.nil?
end

#composing_dm?Boolean

Returns:

  • (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

#getsObject



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

#statusObject



40
41
42
# File 'lib/whatup/server/models/client.rb', line 40

def status
  "#{name}#{chatting? ? " (#{room.name})" : ''}"
end

#to_sObject



59
60
61
# File 'lib/whatup/server/models/client.rb', line 59

def to_s
  name
end