Class: ChatMesage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ ChatMesage

Returns a new instance of ChatMesage.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/models/chat_message.rb', line 6

def initialize(data = {})
  # @mode
  # Type: Integer
  @mode = data[:mode]

  # @client_id
  # Type: Integer
  @client_id = data[:client_id]

  # @target_id
  # Type: Integer
  @target_id = data[:target_id]

  # @message
  # Type: String
  @message = data[:message]

  # @author
  # Type: Player see player.rb
  @author = data[:author]
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



4
5
6
# File 'lib/models/chat_message.rb', line 4

def author
  @author
end

#client_idObject (readonly)

Returns the value of attribute client_id.



4
5
6
# File 'lib/models/chat_message.rb', line 4

def client_id
  @client_id
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/models/chat_message.rb', line 4

def message
  @message
end

#modeObject (readonly)

Returns the value of attribute mode.



4
5
6
# File 'lib/models/chat_message.rb', line 4

def mode
  @mode
end

#target_idObject (readonly)

Returns the value of attribute target_id.



4
5
6
# File 'lib/models/chat_message.rb', line 4

def target_id
  @target_id
end

Instance Method Details

#to_sObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/models/chat_message.rb', line 28

def to_s
  # server message
  return "*** #{@message}" if @client_id == -1

  # player message
  # should never be from an invalid id
  # but lets not crash if servers send weird stuff
  name = ''
  name = @author.name if @author
  "#{name}: #{@message}"
end