Class Jabber::Vcard::IqVcard
In: lib/xmpp4r/vcard/iq/vcard.rb
Parent: XMPPElement

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

Methods

[]   []=   fields   new  

Public Class methods

Initialize a <vCard/> element

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

[Source]

    # File lib/xmpp4r/vcard/iq/vcard.rb, line 20
20:       def initialize(fields=nil)
21:         super()
22: 
23:         unless fields.nil?
24:           fields.each { |name,value|
25:             self[name] = value
26:           }
27:         end
28:       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/vcard/iq/vcard.rb, line 36
36:       def [](name)
37:         text = nil
38:         each_element(name) { |child| text = child.text }
39:         text
40:       end

Set an elements/fields text

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

[Source]

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

Get vCard field names

Example:

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

[Source]

    # File lib/xmpp4r/vcard/iq/vcard.rb, line 71
71:       def fields
72:         element_names(self).uniq
73:       end

[Validate]