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.
Create new XRosterItem from REXML::Element
item: | [REXML::Element] source element to copy attributes and children from |
# File lib/xmpp4r/x/roster.rb, line 66 66: def XRosterItem.import(item) 67: XRosterItem::new.import(item) 68: end
Get action for this roster item
result: | [Symbol] (defaults to :add according to JEP-0144) |
# 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)
# 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 |
# 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 |
# 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] |
# 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 |
# File lib/xmpp4r/x/roster.rb, line 82 82: def iname=(val) 83: attributes['name'] = val 84: end