vCard container for User Information (can be specified by users themselves, mostly kept on servers) (JEP 0054)
Initialize a <vCard/> element
Initialize with keys as XPath element names and values for element texts
# File lib/xmpp4r/vcard/iq/vcard.rb, line 21 def initialize(fields=nil) super() unless fields.nil? fields.each { |name,value| self[name] = value } end 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
XPath
# File lib/xmpp4r/vcard/iq/vcard.rb, line 37 def [](name) text = nil each_element(name) { |child| text = child.text } text end
Set an elements/fields text
XPath
Value
# File lib/xmpp4r/vcard/iq/vcard.rb, line 47 def []=(name, text) xe = self name.split(/\//).each do |elementname| # Does the children already exist? newxe = nil xe.each_element(elementname) { |child| newxe = child } if newxe.nil? # Create a new xe = xe.add_element(elementname) else # Or take existing xe = newxe end end xe.text = text end
Get vCard field names
Example:
["NICKNAME", "BDAY", "ORG/ORGUNIT", "PHOTO/TYPE", "PHOTO/BINVAL"]
of [String]
# File lib/xmpp4r/vcard/iq/vcard.rb, line 72 def fields element_names(self).uniq end
Get the PHOTO/BINVAL (Avatar picture) field decoded from Base64
or [nil]
# File lib/xmpp4r/vcard/iq/vcard.rb, line 79 def photo_binval if (binval = self['PHOTO/BINVAL']) Base64::decode64(binval) else nil end end