class Jabber::Roster::XRosterItem

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.

Public Class Methods

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

Construct a new roster item

jid
JID

Jabber ID

iname
String

Name in the roster

Calls superclass method
# File lib/xmpp4r/roster/x/roster.rb, line 44
def initialize(jid=nil, iname=nil)
  super()
  self.jid = jid
  self.iname = iname
end

Public Instance Methods

action() click to toggle source

Get action for this roster item

  • :add

  • :modify

  • :delete

result
Symbol

(defaults to :add according to JEP-0144)

# File lib/xmpp4r/roster/x/roster.rb, line 87
def action
  case attributes['action']
    when 'modify' then :modify
    when 'delete' then :delete
    else :add
  end
end
action=(a) click to toggle source

Set action for this roster item (see action)

# File lib/xmpp4r/roster/x/roster.rb, line 98
def action=(a)
  case a
    when :modify then attributes['action'] = 'modify'
    when :delete then attributes['action'] = 'delete'
    else attributes['action'] = 'add'
  end
end
groups() click to toggle source

Get groups the item belongs to

result
Array

of [String] The groups

# File lib/xmpp4r/roster/x/roster.rb, line 109
def groups
  result = []
  each_element('group') { |group|
    result.push(group.text)
  }
  result
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/x/roster.rb, line 123
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/x/roster.rb, line 55
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/x/roster.rb, line 62
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/x/roster.rb, line 70
def jid
  JID.new(attributes['jid'])
end
jid=(val) click to toggle source

Set JID of roster item

val
JID

or nil

# File lib/xmpp4r/roster/x/roster.rb, line 77
def jid=(val)
  attributes['jid'] = val.nil? ? nil : val.to_s
end