Class: Warchat::Chat::Presence
- Inherits:
-
Object
- Object
- Warchat::Chat::Presence
- Defined in:
- lib/warchat/chat/presence.rb
Constant Summary collapse
- STATUS_OFFLINE =
'offline'
- STATUS_ONLINE =
'online'
Instance Method Summary collapse
- #character ⇒ Object
- #client_type ⇒ Object
-
#initialize(response) ⇒ Presence
constructor
A new instance of Presence.
- #inspect ⇒ Object
- #offline? ⇒ Boolean
- #status ⇒ Object
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
#character ⇒ Object
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_type ⇒ Object
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 |
#inspect ⇒ Object
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
20 21 22 |
# File 'lib/warchat/chat/presence.rb', line 20 def offline? @type and @type.include? 'offline' end |
#status ⇒ Object
24 25 26 27 |
# File 'lib/warchat/chat/presence.rb', line 24 def status return 'unknown' unless @type @type.split('_').first end |