class Jabber::Roster::RosterItem

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.

Public Class Methods

new(jid=nil, iname=nil, subscription=nil, ask=nil) click to toggle source

Construct a new roster item

jid
JID

Jabber ID

iname
String

Name in the roster

subscription
Symbol

Type of subscription (see #subscription=)

ask
Symbol

or [Nil] Can be :subscribe

Calls superclass method
# 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

Public Instance Methods

ask() click to toggle source

Get if asking for subscription

result
Symbol

nil or :subscribe

# File lib/xmpp4r/roster/iq/roster.rb, line 170
def ask
  case attributes['ask']
    when 'subscribe' then :subscribe
    else nil
  end
end
ask=(val) click to toggle source

Set if asking for subscription

val
Symbol

nil or :subscribe

# 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
groups() click to toggle source

Get groups the item belongs to

result
Array

of [String] The groups

# 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) click to toggle source

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/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
iname() click to toggle source

Get name of roster item

names can be set by the roster's owner himself

return
String
# File lib/xmpp4r/roster/iq/roster.rb, line 108
def iname
  attributes['name']
end
iname=(val) click to toggle source

Set name of roster item

val
String

Name for this item

# File lib/xmpp4r/roster/iq/roster.rb, line 115
def iname=(val)
  attributes['name'] = val
end
jid() click to toggle source

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

return
JID
# File lib/xmpp4r/roster/iq/roster.rb, line 123
def jid
  (a = attributes['jid']) ? JID.new(a) : nil
end
jid=(val) click to toggle source

Set JID of roster item

val
JID

or nil

# File lib/xmpp4r/roster/iq/roster.rb, line 130
def jid=(val)
  attributes['jid'] = val.nil? ? nil : val.to_s
end
subscription() click to toggle source

Get subscription type of roster item

result
Symbol

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

  • :both

  • :from

  • :none

  • :remove

  • :to

# 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) click to toggle source

Set subscription type of roster item

val
Symbol

or [Nil] See subscription for possible Symbols

# 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