| Class | Jabber::Vcard::IqVcard |
| In: |
lib/xmpp4r/vcard/iq/vcard.rb
|
| Parent: | REXML::Element |
vCard container for User Information (can be specified by users themselves, mostly kept on servers) (JEP 0054)
| element: | [REXML::Element] to import |
| result: | [IqVcard] with all attributes and children copied from element |
# File lib/xmpp4r/vcard/iq/vcard.rb, line 31
31: def IqVcard.import(element)
32: IqVcard::new.import(element)
33: end
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 17
17: def initialize(fields=nil)
18: super("vCard")
19: add_namespace('vcard-temp')
20:
21: unless fields.nil?
22: fields.each { |name,value|
23: self[name] = value
24: }
25: end
26: 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 41
41: def [](name)
42: text = nil
43: each_element(name) { |child| text = child.text }
44: text
45: end
Set an elements/fields text
| name: | [String] XPath |
| text: | [String] Value |
# File lib/xmpp4r/vcard/iq/vcard.rb, line 51
51: def []=(name, text)
52: xe = self
53: name.split(/\//).each do |elementname|
54: # Does the children already exist?
55: newxe = nil
56: xe.each_element(elementname) { |child| newxe = child }
57:
58: if newxe.nil?
59: # Create a new
60: xe = xe.add_element(elementname)
61: else
62: # Or take existing
63: xe = newxe
64: end
65: end
66: xe.text = text
67: end