Class: Jabber::Dataforms::XDataField
- Inherits:
-
XMPPElement
- Object
- REXML::Element
- XMPPElement
- Jabber::Dataforms::XDataField
- Defined in:
- lib/xmpp4r/dataforms/x/data.rb
Overview
Child of XData, contains configurable/configured options of this Data Form
Instance Method Summary collapse
-
#initialize(var = nil, type = nil) ⇒ XDataField
constructor
A new instance of XDataField.
- #label ⇒ Object
- #label=(s) ⇒ Object
-
#options ⇒ Object
Get the options (in a Data Form with type=‘form’).
-
#options=(hsh) ⇒ Object
Set the options.
-
#required=(r) ⇒ Object
- Set if this field is required r
- true
-
or [false].
-
#required? ⇒ Boolean
Is this field required (has the <required/> child)?.
-
#type ⇒ Object
- Type of this field result
-
:boolean * :fixed * :hidden * :jid_multi * :jid_single * :list_multi * :list_single * :text_multi * :text_private * :text_single * nil.
-
-
#type=(t) ⇒ Object
Set the type of this field (see type).
-
#value ⇒ Object
Get the first value.
-
#value=(val) ⇒ Object
Remove all and set one value.
-
#values ⇒ Object
Get the values (in a Data Form with type=‘submit’).
-
#values=(ary) ⇒ Object
Set the values.
- #var ⇒ Object
- #var=(s) ⇒ Object
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(var = nil, type = nil) ⇒ XDataField
Returns a new instance of XDataField.
148 149 150 151 152 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 148 def initialize(var=nil, type=nil) super() self.var = var self.type = type end |
Instance Method Details
#label ⇒ Object
154 155 156 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 154 def label attributes['label'] end |
#label=(s) ⇒ Object
158 159 160 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 158 def label=(s) attributes['label'] = s end |
#options ⇒ Object
Get the options (in a Data Form with type=‘form’)
269 270 271 272 273 274 275 276 277 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 269 def res = {} each_element('option') { |e| value = nil e.each_element('value') { |ve| value = ve.text } res[value] = e.attributes['label'] } res end |
#options=(hsh) ⇒ Object
Set the options
281 282 283 284 285 286 287 288 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 281 def (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) ⇒ Object
Set if this field is required
- r
- true
-
or [false]
229 230 231 232 233 234 |
# 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? ⇒ Boolean
Is this field required (has the <required/> child)?
220 221 222 223 224 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 220 def required? res = false each_element('required') { res = true } res end |
#type ⇒ Object
Type of this field
- result
-
:boolean
-
:fixed
-
:hidden
-
:jid_multi
-
:jid_single
-
:list_multi
-
:list_single
-
:text_multi
-
:text_private
-
:text_single
-
nil
-
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# 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) ⇒ Object
Set the type of this field (see type)
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# 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 ⇒ Object
Get the first value
257 258 259 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 257 def value values.first end |
#value=(val) ⇒ Object
Remove all and set one value
263 264 265 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 263 def value=(val) self.values = [val] end |
#values ⇒ Object
Get the values (in a Data Form with type=‘submit’)
238 239 240 241 242 243 244 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 238 def values res = [] each_element('value') { |e| res << e.text } res end |
#values=(ary) ⇒ Object
Set the values
248 249 250 251 252 253 |
# 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 ⇒ Object
162 163 164 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 162 def var attributes['var'] end |
#var=(s) ⇒ Object
166 167 168 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 166 def var=(s) attributes['var'] = s end |