Class Jabber::IqVcard
In: lib/xmpp4r/iq/vcard.rb
Parent: REXML::Element

vCard container for User Information (can be specified by users themselves, mostly kept on servers) (JEP 0054)

Methods

[]   []=   fields   import   new  

Public Class methods

element:[REXML::Element] to import
result:[IqVcard] with all attributes and children copied from element

[Source]

    # File lib/xmpp4r/iq/vcard.rb, line 30
30:     def IqVcard.import(element)
31:       IqVcard::new.import(element)
32:     end

Initialize a <vCard/> element

fields:[Hash] Initialize with keys as XPath element names and values for element texts

[Source]

    # File lib/xmpp4r/iq/vcard.rb, line 16
16:     def initialize(fields=nil)
17:       super("vCard")
18:       add_namespace('vcard-temp')
19: 
20:       unless fields.nil?
21:         fields.each { |name,value|
22:           self[name] = value
23:         }
24:       end
25:     end

Public Instance methods

Get an elements/fields text

vCards have too much possible children, so ask for them here and extract the result with iqvcard.element(’…’).text

name:[String] XPath

[Source]

    # File lib/xmpp4r/iq/vcard.rb, line 40
40:     def [](name)
41:       text = nil
42:       each_element(name) { |child| text = child.text }
43:       text
44:     end

Set an elements/fields text

name:[String] XPath
text:[String] Value

[Source]

    # File lib/xmpp4r/iq/vcard.rb, line 50
50:     def []=(name, text)
51:       xe = self
52:       name.split(/\//).each do |elementname|
53:         # Does the children already exist?
54:         newxe = nil
55:         xe.each_element(elementname) { |child| newxe = child }
56: 
57:         if newxe.nil?
58:           # Create a new
59:           xe = xe.add_element(elementname)
60:         else
61:           # Or take existing
62:           xe = newxe
63:         end
64:       end
65:       xe.text = text
66:     end

Get vCard field names

Example:

 ["NICKNAME", "BDAY", "ORG/ORGUNIT", "PHOTO/TYPE", "PHOTO/BINVAL"]
result:[Array] of [String]

[Source]

    # File lib/xmpp4r/iq/vcard.rb, line 75
75:     def fields
76:       element_names(self).uniq
77:     end

[Validate]