Class: Jabber::Roster::XRosterItem

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

Overview

Class containing an 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.

Direct Known Subclasses

RosterXItem

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) ⇒ XRosterItem

Construct a new roster item

jid

[JID] Jabber ID

iname

[String] Name in the roster



44
45
46
47
48
# File 'lib/xmpp4r/roster/x/roster.rb', line 44

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

Instance Method Details

#actionObject

Get action for this roster item

  • :add
  • :modify
  • :delete
result

[Symbol] (defaults to :add according to JEP-0144)



87
88
89
90
91
92
93
# 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) ⇒ Object

Set action for this roster item (see action)



98
99
100
101
102
103
104
# 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

#groupsObject

Get groups the item belongs to

result

[Array] of [String] The groups



109
110
111
112
113
114
115
# File 'lib/xmpp4r/roster/x/roster.rb', line 109

def groups
  result = []
  each_element('group') { |group|
    result.push(group.text)
  }
  result
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



123
124
125
126
127
128
129
130
131
# 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

#inameObject

Get name of roster item

names can be set by the roster's owner himself

return

[String]



55
56
57
# File 'lib/xmpp4r/roster/x/roster.rb', line 55

def iname
  attributes['name']
end

#iname=(val) ⇒ Object

Set name of roster item

val

[String] Name for this item



62
63
64
# File 'lib/xmpp4r/roster/x/roster.rb', line 62

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

#jidObject

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

return

[JID]



70
71
72
# File 'lib/xmpp4r/roster/x/roster.rb', line 70

def jid
  JID.new(attributes['jid'])
end

#jid=(val) ⇒ Object

Set JID of roster item

val

[JID] or nil



77
78
79
# File 'lib/xmpp4r/roster/x/roster.rb', line 77

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