class Jabber::Dataforms::XDataField

Child of XData, contains configurable/configured options of this Data Form

Public Class Methods

new(var=nil, type=nil) click to toggle source
Calls superclass method
# File lib/xmpp4r/dataforms/x/data.rb, line 148
def initialize(var=nil, type=nil)
  super()
  self.var = var
  self.type = type
end

Public Instance Methods

label() click to toggle source
# File lib/xmpp4r/dataforms/x/data.rb, line 154
def label
  attributes['label']
end
label=(s) click to toggle source
# File lib/xmpp4r/dataforms/x/data.rb, line 158
def label=(s)
  attributes['label'] = s
end
options() click to toggle source

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
options=(hsh) click to toggle source

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
required=(r) click to toggle source

Set if this field is required

r
true

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

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

Type of this field

result
  • :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
type=(t) click to toggle source

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

Get the first value

# File lib/xmpp4r/dataforms/x/data.rb, line 257
def value
  values.first
end
value=(val) click to toggle source

Remove all and set one value

# File lib/xmpp4r/dataforms/x/data.rb, line 263
def value=(val)
  self.values = [val]
end
values() click to toggle source

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
values=(ary) click to toggle source

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
var() click to toggle source
# File lib/xmpp4r/dataforms/x/data.rb, line 162
def var
  attributes['var']
end
var=(s) click to toggle source
# File lib/xmpp4r/dataforms/x/data.rb, line 166
def var=(s)
  attributes['var'] = s
end