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)
element: | [REXML::Element] to import |
result: | [IqVcard] with all attributes and children copied from element |
# 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 |
# 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
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/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 |
# 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