Class: Jabber::Roster::RosterItem

Inherits:
XMPPElement show all
Defined in:
lib/xmpp4r/roster/iq/roster.rb

Overview

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.

Direct Known Subclasses

Helper::RosterItem

Instance Method Summary collapse

Methods inherited from XMPPElement

class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=

Methods inherited from REXML::Element

#==, #delete_elements, #each_elements, #first_element, #first_element_content, #first_element_text, #import, import, #replace_element_content, #replace_element_text, #typed_add

Constructor Details

#initialize(jid = nil, iname = nil, subscription = nil, ask = nil) ⇒ RosterItem

Construct a new roster item

jid
JID

Jabber ID

iname
String

Name in the roster

subscription
Symbol

Type of subscription (see RosterItem#subscription=)

ask
Symbol

or [Nil] Can be :subscribe



95
96
97
98
99
100
101
# File 'lib/xmpp4r/roster/iq/roster.rb', line 95

def initialize(jid=nil, iname=nil, subscription=nil, ask=nil)
  super()
  self.jid = jid
  self.iname = iname
  self.subscription = subscription
  self.ask = ask
end

Instance Method Details

#askObject

Get if asking for subscription

result
Symbol

nil or :subscribe



170
171
172
173
174
175
# File 'lib/xmpp4r/roster/iq/roster.rb', line 170

def ask
  case attributes['ask']
    when 'subscribe' then :subscribe
    else nil
  end
end

#ask=(val) ⇒ Object

Set if asking for subscription

val
Symbol

nil or :subscribe



180
181
182
183
184
185
# File 'lib/xmpp4r/roster/iq/roster.rb', line 180

def ask=(val)
  case val
    when :subscribe then attributes['ask'] = 'subscribe'
    else attributes['ask'] = nil
  end
end

#groupsObject

Get groups the item belongs to

result
Array

of [String] The groups



190
191
192
193
194
195
196
# File 'lib/xmpp4r/roster/iq/roster.rb', line 190

def groups
  result = []
  each_element('group') { |group|
    result.push(group.text)
  }
  result.uniq
end

#groups=(ary) ⇒ Object

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



204
205
206
207
208
209
210
211
212
# File 'lib/xmpp4r/roster/iq/roster.rb', line 204

def groups=(ary)
  # Delete old group elements
  delete_elements('group')

  # Add new group elements
  ary.uniq.each { |group|
    add_element('group').text = group
  }
end

#inameObject

Get name of roster item

names can be set by the roster's owner himself

return
String


108
109
110
# File 'lib/xmpp4r/roster/iq/roster.rb', line 108

def iname
  attributes['name']
end

#iname=(val) ⇒ Object

Set name of roster item

val
String

Name for this item



115
116
117
# File 'lib/xmpp4r/roster/iq/roster.rb', line 115

def iname=(val)
  attributes['name'] = val
end

#jidObject

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

return
JID


123
124
125
# File 'lib/xmpp4r/roster/iq/roster.rb', line 123

def jid
  (a = attributes['jid']) ? JID.new(a) : nil
end

#jid=(val) ⇒ Object

Set JID of roster item

val
JID

or nil



130
131
132
# File 'lib/xmpp4r/roster/iq/roster.rb', line 130

def jid=(val)
  attributes['jid'] = val.nil? ? nil : val.to_s
end

#subscriptionObject

Get subscription type of roster item

result
Symbol

or [Nil] The following values are valid according to RFC3921:

  • :both

  • :from

  • :none

  • :remove

  • :to



142
143
144
145
146
147
148
149
150
151
# File 'lib/xmpp4r/roster/iq/roster.rb', line 142

def subscription
  case attributes['subscription']
    when 'both' then :both
    when 'from' then :from
    when 'none' then :none
    when 'remove' then :remove
    when 'to' then :to
    else nil
  end
end

#subscription=(val) ⇒ Object

Set subscription type of roster item

val
Symbol

or [Nil] See subscription for possible Symbols



156
157
158
159
160
161
162
163
164
165
# File 'lib/xmpp4r/roster/iq/roster.rb', line 156

def subscription=(val)
  case val
    when :both then attributes['subscription'] = 'both'
    when :from then attributes['subscription'] = 'from'
    when :none then attributes['subscription'] = 'none'
    when :remove then attributes['subscription'] = 'remove'
    when :to then attributes['subscription'] = 'to'
    else attributes['subscription'] = nil
  end
end