class Jabber::Vcard::IqVcard

vCard container for User Information (can be specified by users themselves, mostly kept on servers) (JEP 0054)

Public Class Methods

new(fields=nil) click to toggle source

Initialize a <vCard/> element

fields
Hash

Initialize with keys as XPath element names and values for element texts

Calls superclass method
# 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

Public Instance Methods

[](name) click to toggle source

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
def [](name)
  text = nil
  each_element(name) { |child| text = child.text }
  text
end
[]=(name, text) click to toggle source

Set an elements/fields text

name
String

XPath

text
String

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
fields() click to toggle source

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
def fields
  element_names(self).uniq
end
photo_binval() click to toggle source

Get the PHOTO/BINVAL (Avatar picture) field decoded from Base64

result
String

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