Child of XData, contains configurable/configured options of this Data Form
# File lib/xmpp4r/dataforms/x/data.rb, line 148 def initialize(var=nil, type=nil) super() self.var = var self.type = type end
# File lib/xmpp4r/dataforms/x/data.rb, line 154 def label attributes['label'] end
# File lib/xmpp4r/dataforms/x/data.rb, line 158 def label=(s) attributes['label'] = s end
Get the options (in a Data Form with type='form')
# File lib/xmpp4r/dataforms/x/data.rb, line 269 def options res = {} each_element('option') { |e| value = nil e.each_element('value') { |ve| value = ve.text } res[value] = e.attributes['label'] } res end
Set the options
# File lib/xmpp4r/dataforms/x/data.rb, line 281 def options=(hsh) delete_elements('option') hsh.each { |value,label| o = add(REXML::Element.new('option')) o.attributes['label'] = label o.add(REXML::Element.new('value')).text = value } end
Set if this field is required
or [false]
# File lib/xmpp4r/dataforms/x/data.rb, line 229 def required=(r) delete_elements('required') if r add REXML::Element.new('required') end end
Is this field required (has the <required/> child)?
# File lib/xmpp4r/dataforms/x/data.rb, line 220 def required? res = false each_element('required') { res = true } res end
Type of this field
:boolean
:fixed
:hidden
:jid_multi
:jid_single
:list_multi
:list_single
:text_multi
:text_private
:text_single
nil
# File lib/xmpp4r/dataforms/x/data.rb, line 184 def type case attributes['type'] when 'boolean' then :boolean when 'fixed' then :fixed when 'hidden' then :hidden when 'jid-multi' then :jid_multi when 'jid-single' then :jid_single when 'list-multi' then :list_multi when 'list-single' then :list_single when 'text-multi' then :text_multi when 'text-private' then :text_private when 'text-single' then :text_single else nil end end
Set the type of this field (see type)
# File lib/xmpp4r/dataforms/x/data.rb, line 202 def type=(t) case t when :boolean then attributes['type'] = 'boolean' when :fixed then attributes['type'] = 'fixed' when :hidden then attributes['type'] = 'hidden' when :jid_multi then attributes['type'] = 'jid-multi' when :jid_single then attributes['type'] = 'jid-single' when :list_multi then attributes['type'] = 'list-multi' when :list_single then attributes['type'] = 'list-single' when :text_multi then attributes['type'] = 'text-multi' when :text_private then attributes['type'] = 'text-private' when :text_single then attributes['type'] = 'text-single' else attributes['type'] = nil end end
Get the first value
# File lib/xmpp4r/dataforms/x/data.rb, line 257 def value values.first end
Remove all and set one value
# File lib/xmpp4r/dataforms/x/data.rb, line 263 def value=(val) self.values = [val] end
Get the values (in a Data Form with type='submit')
# File lib/xmpp4r/dataforms/x/data.rb, line 238 def values res = [] each_element('value') { |e| res << e.text } res end
Set the values
# File lib/xmpp4r/dataforms/x/data.rb, line 248 def values=(ary) delete_elements('value') ary.each { |v| add(REXML::Element.new('value')).text = v } end
# File lib/xmpp4r/dataforms/x/data.rb, line 162 def var attributes['var'] end
# File lib/xmpp4r/dataforms/x/data.rb, line 166 def var=(s) attributes['var'] = s end