| Class | Jabber::RosterItem |
| In: |
lib/xmpp4r/iq/query/roster.rb
|
| Parent: | REXML::Element |
Class containing the <item/> elements of the roster
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.
Create new RosterItem from REXML::Element
| item: | [REXML::Element] source element to copy attributes and children from |
# File lib/xmpp4r/iq/query/roster.rb, line 125
125: def RosterItem.import(item)
126: RosterItem::new.import(item)
127: end
Construct a new roster item
| jid: | [JID] Jabber ID |
| iname: | [String] Name in the roster |
| subscription: | [String] Type of subscription (see RosterItem#subscription=) |
| ask: | [String] or [Nil] Can be "ask" |
# File lib/xmpp4r/iq/query/roster.rb, line 114
114: def initialize(jid=nil, iname=nil, subscription=nil, ask=nil)
115: super('item')
116: self.jid = jid
117: self.iname = iname
118: self.subscription = subscription
119: self.ask = ask
120: end
Get if asking for subscription
| result: | [Symbol] nil or :subscribe |
# File lib/xmpp4r/iq/query/roster.rb, line 196
196: def ask
197: case attributes['ask']
198: when 'subscribe' then :subscribe
199: else nil
200: end
201: end
Set if asking for subscription
| val: | [Symbol] nil or :subscribe |
# File lib/xmpp4r/iq/query/roster.rb, line 206
206: def ask=(val)
207: case val
208: when :subscribe then attributes['ask'] = 'subscribe'
209: else attributes['ask'] = nil
210: end
211: end
Get groups the item belongs to
| result: | [Array] of [String] The groups |
# File lib/xmpp4r/iq/query/roster.rb, line 216
216: def groups
217: result = []
218: each_element('group') { |group|
219: result.push(group.text)
220: }
221: result
222: 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/iq/query/roster.rb, line 230
230: def groups=(ary)
231: # Delete old group elements
232: delete_elements('group')
233:
234: # Add new group elements
235: ary.uniq.each { |group|
236: add_element('group').text = group
237: }
238: end
Get name of roster item
names can be set by the roster’s owner himself
| return: | [String] |
# File lib/xmpp4r/iq/query/roster.rb, line 134
134: def iname
135: attributes['name']
136: end
Set name of roster item
| val: | [String] Name for this item |
# File lib/xmpp4r/iq/query/roster.rb, line 141
141: def iname=(val)
142: attributes['name'] = val
143: end
Get subscription type of roster item
| result: | [Symbol] or [Nil] The following values are valid according to RFC3921: |
# File lib/xmpp4r/iq/query/roster.rb, line 168
168: def subscription
169: case attributes['subscription']
170: when 'both' then :both
171: when 'from' then :from
172: when 'none' then :none
173: when 'remove' then :remove
174: when 'to' then :to
175: else nil
176: end
177: end
Set subscription type of roster item
| val: | [Symbol] or [Nil] See subscription for possible Symbols |
# File lib/xmpp4r/iq/query/roster.rb, line 182
182: def subscription=(val)
183: case val
184: when :both then attributes['subscription'] = 'both'
185: when :from then attributes['subscription'] = 'from'
186: when :none then attributes['subscription'] = 'none'
187: when :remove then attributes['subscription'] = 'remove'
188: when :to then attributes['subscription'] = 'to'
189: else attributes['subscription'] = nil
190: end
191: end