Class: Jabber::Vcard::IqVcard
- Inherits:
-
XMPPElement
- Object
- REXML::Element
- XMPPElement
- Jabber::Vcard::IqVcard
- Defined in:
- lib/xmpp4r/vcard/iq/vcard.rb
Overview
vCard container for User Information (can be specified by users themselves, mostly kept on servers) (JEP 0054)
Instance Method Summary collapse
-
#[](name) ⇒ Object
Get an elements/fields text.
-
#[]=(name, text) ⇒ Object
- Set an elements/fields text name
- String
- XPath text
- String
-
Value.
-
#fields ⇒ Object
Get vCard field names.
-
#initialize(fields = nil) ⇒ IqVcard
constructor
- Initialize a <vCard/> element fields
- Hash
-
Initialize with keys as XPath element names and values for element texts.
-
#photo_binval ⇒ Object
- Get the PHOTO/BINVAL (Avatar picture) field decoded from Base64 result
- String
-
or [nil].
Methods inherited from XMPPElement
class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=
Methods inherited from REXML::Element
#==, #delete_elements, #each_elements, #first_element, #first_element_content, #first_element_text, #import, import, #replace_element_content, #replace_element_text, #typed_add
Constructor Details
#initialize(fields = nil) ⇒ IqVcard
Initialize a <vCard/> element
- fields
- Hash
-
Initialize with keys as XPath element names and values for element texts
21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Method Details
#[](name) ⇒ Object
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
37 38 39 40 41 |
# File 'lib/xmpp4r/vcard/iq/vcard.rb', line 37 def [](name) text = nil each_element(name) { |child| text = child.text } text end |
#[]=(name, text) ⇒ Object
Set an elements/fields text
- name
- String
-
XPath
- text
- String
-
Value
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
Get vCard field names
Example:
["NICKNAME", "BDAY", "ORG/ORGUNIT", "PHOTO/TYPE", "PHOTO/BINVAL"]
- result
- Array
-
of [String]
72 73 74 |
# File 'lib/xmpp4r/vcard/iq/vcard.rb', line 72 def fields element_names(self).uniq end |
#photo_binval ⇒ Object
Get the PHOTO/BINVAL (Avatar picture) field decoded from Base64
- result
- String
-
or [nil]
79 80 81 82 83 84 85 |
# File 'lib/xmpp4r/vcard/iq/vcard.rb', line 79 def photo_binval if (binval = self['PHOTO/BINVAL']) Base64::decode64(binval) else nil end end |