| 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)
Initialize a <vCard/> element
| fields: | [Hash] Initialize with keys as XPath element names and values for element texts |
# File lib/xmpp4r/vcard/iq/vcard.rb, line 21
21: def initialize(fields=nil)
22: super()
23:
24: unless fields.nil?
25: fields.each { |name,value|
26: self[name] = value
27: }
28: end
29: end
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 |
# File lib/xmpp4r/vcard/iq/vcard.rb, line 37
37: def [](name)
38: text = nil
39: each_element(name) { |child| text = child.text }
40: text
41: end
Set an elements/fields text
| name: | [String] XPath |
| text: | [String] Value |
# File lib/xmpp4r/vcard/iq/vcard.rb, line 47
47: def []=(name, text)
48: xe = self
49: name.split(/\//).each do |elementname|
50: # Does the children already exist?
51: newxe = nil
52: xe.each_element(elementname) { |child| newxe = child }
53:
54: if newxe.nil?
55: # Create a new
56: xe = xe.add_element(elementname)
57: else
58: # Or take existing
59: xe = newxe
60: end
61: end
62: xe.text = text
63: end
Get vCard field names
Example:
["NICKNAME", "BDAY", "ORG/ORGUNIT", "PHOTO/TYPE", "PHOTO/BINVAL"]
| result: | [Array] of [String] |
# File lib/xmpp4r/vcard/iq/vcard.rb, line 72
72: def fields
73: element_names(self).uniq
74: end