Class Jabber::XRosterItem
In: lib/xmpp4r/x/roster.rb
Parent: REXML::Element

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]