| 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 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
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 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 |
# 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