Class: Warchat::Chat::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/warchat/chat/message.rb

Constant Summary collapse

CHAT_MSG_TYPE_AFK =
"afk"
CHAT_MSG_TYPE_DND =
"dnd"
CHAT_MSG_TYPE_GUILD_CHAT =
"guild_chat"
CHAT_MSG_TYPE_GUILD_MOTD =
"motd"
CHAT_MSG_TYPE_OFFICER_CHAT =
"officer_chat"
CHAT_MSG_TYPE_WHISPER =
"whisper"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Message

Returns a new instance of Message.



14
15
16
17
18
19
# File 'lib/warchat/chat/message.rb', line 14

def initialize response
  @response = response 
  @type = response["messageType"]
  @body = response['body']
  @from = (response["from"] or {})
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/warchat/chat/message.rb', line 12

def body
  @body
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/warchat/chat/message.rb', line 12

def type
  @type
end

Instance Method Details

#characterObject



27
28
29
30
31
# File 'lib/warchat/chat/message.rb', line 27

def character
  return @character if @character or @from["characterId"].nil?
  _,name,realm = @from["characterId"].split(':')
  @character = Warchat::Models::Character.find_or_create 'n' => name,'r'=>realm
end

#guildObject



21
22
23
24
25
# File 'lib/warchat/chat/message.rb', line 21

def guild
  return @guild if @guild or @from["guildId"].nil?
  _,name,realm = @response['from']["guildId"].split(':')
  @guild = Warchat::Models::Guild.find_or_create 'n' => name,'r'=>realm
end