Class: XMPPBot::Presence

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stanza = nil) ⇒ Presence

Returns a new instance of Presence.



11
12
13
14
15
16
17
18
# File 'lib/xmppbot/presence.rb', line 11

def initialize(stanza=nil)
  if stanza
    @stanza=stanza
  else
    @stanza = StropheRuby::Stanza.new
    @stanza.name = "presence"
  end
end

Instance Attribute Details

#stanzaObject (readonly)

Returns the value of attribute stanza.



9
10
11
# File 'lib/xmppbot/presence.rb', line 9

def stanza
  @stanza
end

Instance Method Details

#fromObject



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

def from
  self.stanza.attribute("from")
end

#showObject



40
41
42
43
# File 'lib/xmppbot/presence.rb', line 40

def show
  s=self.stanza.child_by_name("show")
  s ? s.text : nil
end

#toObject



24
25
26
# File 'lib/xmppbot/presence.rb', line 24

def to
  self.stanza.attribute("to")
end

#to=(to) ⇒ Object



28
29
30
# File 'lib/xmppbot/presence.rb', line 28

def to=(to)
  self.stanza.set_attribute("to",to)
end

#to_sObject

returns the show (away, dnd, chat,xa). if there is none, returns the type which can be : unavailable subscribe,subscribed,unsubscribe,unsubscribed,probe or error.



47
48
49
50
# File 'lib/xmppbot/presence.rb', line 47

def to_s
  res = self.show
  res ? res : self.type ? self.type : "available"
end

#typeObject



32
33
34
# File 'lib/xmppbot/presence.rb', line 32

def type
  self.stanza.type
end

#type=(type) ⇒ Object



36
37
38
# File 'lib/xmppbot/presence.rb', line 36

def type=(type)
  self.stanza.type=type
end