Class Jabber::XRosterItem
In: lib/xmpp4r/x/roster.rb
Parent: REXML::Element
X XDelay XMuc XRoster XMucUser REXML::Element XRosterItem IqQuery XMLStanza IqVcard DiscoIdentity XMucUserItem DiscoItem Error RosterItem DiscoFeature IqQueryRoster IqQueryVersion IqQueryDiscoItems IqQueryDiscoInfo Message Presence Iq Singleton IdGenerator Connection Client Component Comparable JID RuntimeError ErrorException AuthenticationFailure RosterItem Stream StreamParser Roster Vcard Version lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/iq/query/roster.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/iq/query/version.rb lib/xmpp4r/connection.rb lib/xmpp4r/x/mucuseritem.rb lib/xmpp4r/x/roster.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/iq/query.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/x/delay.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/x/muc.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/iq/vcard.rb lib/xmpp4r/iq/query/discoinfo.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/message.rb lib/xmpp4r/iq/query/discoitems.rb lib/xmpp4r/presence.rb lib/xmpp4r/helpers/roster.rb lib/xmpp4r/helpers/vcard.rb lib/xmpp4r/helpers/version.rb Helpers Jabber Module: Jabber

Class containing an <item/> element

The ‘name’ attribute has been renamed to ‘iname’ here as ‘name’ is already used by REXML::Element for the element’s name. It’s still name=’…’ in XML.

This is all a bit analoguous to Jabber::RosterItem, used by Jabber::IqQueryRoster. But this class lacks the subscription and ask attributes.

Methods

action   action=   groups   groups=   import   iname   iname=   jid   jid=   new  

Public Class methods

Create new XRosterItem from REXML::Element

item:[REXML::Element] source element to copy attributes and children from

[Source]

    # File lib/xmpp4r/x/roster.rb, line 66
66:     def XRosterItem.import(item)
67:       XRosterItem::new.import(item)
68:     end

Construct a new roster item

jid:[JID] Jabber ID
iname:[String] Name in the roster

[Source]

    # File lib/xmpp4r/x/roster.rb, line 57
57:     def initialize(jid=nil, iname=nil)
58:       super('item')
59:       self.jid = jid
60:       self.iname = iname
61:     end

Public Instance methods

Get action for this roster item

  • :add
  • :modify
  • :delete
result:[Symbol] (defaults to :add according to JEP-0144)

[Source]

     # File lib/xmpp4r/x/roster.rb, line 107
107:     def action
108:       case attributes['action']
109:         when 'modify' then :modify
110:         when 'delete' then :delete
111:         else :add
112:       end
113:     end

Set action for this roster item (see action)

[Source]

     # File lib/xmpp4r/x/roster.rb, line 118
118:     def action=(a)
119:       case a
120:         when :modify then attributes['action'] = 'modify'
121:         when :delete then attributes['action'] = 'delete'
122:         else attributes['action'] = 'add'
123:       end
124:     end

Get groups the item belongs to

result:[Array] of [String] The groups

[Source]

     # File lib/xmpp4r/x/roster.rb, line 129
129:     def groups
130:       result = []
131:       each_element('group') { |group|
132:         result.push(group.text)
133:       }
134:       result
135:     end

Set groups the item belongs to, deletes old groups first.

See JEP 0083 for nested groups

ary:[Array] New groups, duplicate values will be removed

[Source]

     # File lib/xmpp4r/x/roster.rb, line 143
143:     def groups=(ary)
144:       # Delete old group elements
145:       delete_elements('group')
146: 
147:       # Add new group elements
148:       ary.uniq.each { |group|
149:         add_element('group').text = group
150:       }
151:     end

Get name of roster item

names can be set by the roster’s owner himself

return:[String]

[Source]

    # File lib/xmpp4r/x/roster.rb, line 75
75:     def iname
76:       attributes['name']
77:     end

Set name of roster item

val:[String] Name for this item

[Source]

    # File lib/xmpp4r/x/roster.rb, line 82
82:     def iname=(val)
83:       attributes['name'] = val
84:     end

Get JID of roster item Resource of the JID will not be stripped

return:[JID]

[Source]

    # File lib/xmpp4r/x/roster.rb, line 90
90:     def jid
91:       JID::new(attributes['jid'])
92:     end

Set JID of roster item

val:[JID] or nil

[Source]

    # File lib/xmpp4r/x/roster.rb, line 97
97:     def jid=(val)
98:       attributes['jid'] = val.nil? ? nil : val.to_s
99:     end

[Validate]