Class: Jabber::Vcard::IqVcard

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)

### Methods

[] []= fields new photo_binval

### Public Class methods

new(fields=nil)

Initialize a <vCard/> element

fields: | [Hash] Initialize with keys as XPath element names and values for element texts

[Source]

        # File lib/xmpp4r/vcard/iq/vcard.rb, line 21
    21:       def initialize(fields=nil)
    22:         super()
    23:
    24:         unless fields.nil?
    25:           fields.each { |name,value|
    26:             self[name] = value
    27:           }
    28:         end
    29:       end

### Public Instance methods

[](name)

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

[Source]

        # File lib/xmpp4r/vcard/iq/vcard.rb, line 37
    37:       def [](name)
    38:         text = nil
    39:         each_element(name) { |child| text = child.text }
    40:         text
    41:       end

[]=(name, text)

Set an elements/fields text

name: | [String] XPath
text: | [String] Value

[Source]

        # File lib/xmpp4r/vcard/iq/vcard.rb, line 47
    47:       def []=(name, text)
    48:         xe = self
    49:         name.split(/\//).each do |elementname|
    50:           # Does the children already exist?
    51:           newxe = nil
    52:           xe.each_element(elementname) { |child| newxe = child }
    53:
    54:           if newxe.nil?
    55:             # Create a new
    56:             xe = xe.add_element(elementname)
    57:           else
    58:             # Or take existing
    59:             xe = newxe
    60:           end
    61:         end
    62:         xe.text = text
    63:       end

fields()

Get vCard field names

Example:

     ["NICKNAME", "BDAY", "ORG/ORGUNIT", "PHOTO/TYPE", "PHOTO/BINVAL"]

result: | [Array] of [String]

[Source]

        # File lib/xmpp4r/vcard/iq/vcard.rb, line 72
    72:       def fields
    73:         element_names(self).uniq
    74:       end

photo_binval()

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

result: | [String] or [nil]

[Source]

        # File lib/xmpp4r/vcard/iq/vcard.rb, line 79
    79:       def photo_binval
    80:         if (binval = self['PHOTO/BINVAL'])
    81:           Base64::decode64(binval)
    82:         else
    83:           nil
    84:         end
    85:       end

[Validate]