Class: Warchat::Chat::Presence

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

Constant Summary collapse

STATUS_OFFLINE =
'offline'
STATUS_ONLINE =
'online'

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Presence

Returns a new instance of Presence.



8
9
10
11
12
13
14
# File 'lib/warchat/chat/presence.rb', line 8

def initialize response
  @response = response
  @type = response["presenceType"]

  character.respond_to? status.to_sym and character.send status.to_sym
  
end

Instance Method Details

#characterObject



16
17
18
# File 'lib/warchat/chat/presence.rb', line 16

def character
  @character ||= (@response["character"] and Warchat::Models::Character.find_or_create(@response["character"]) or nil)
end

#client_typeObject



29
30
31
32
# File 'lib/warchat/chat/presence.rb', line 29

def client_type 
  return 'unknown' unless @type
  @type.split('_')[1..-1].join '_'
end

#inspectObject



34
35
36
# File 'lib/warchat/chat/presence.rb', line 34

def inspect
  "<#{self.class.name} character:#{character.inspect} status:#{status.inspect} client_type:#{client_type.inspect}>"
end

#offline?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/warchat/chat/presence.rb', line 20

def offline?
  @type and @type.include? 'offline'
end

#statusObject



24
25
26
27
# File 'lib/warchat/chat/presence.rb', line 24

def status 
  return 'unknown' unless @type
  @type.split('_').first
end