Class: Jabber::Dataforms::XData
- Inherits:
-
X
- Object
- REXML::Element
- XMPPElement
- X
- Jabber::Dataforms::XData
- Defined in:
- lib/xmpp4r/dataforms/x/data.rb
Overview
Data Forms (JEP-0004) implementation
Instance Method Summary collapse
-
#field(var) ⇒ Object
- Search a field by it’s var-name var
- String
- result
- XDataField
-
or [nil].
- #fields(including_hidden = false) ⇒ Object
-
#initialize(type = nil) ⇒ XData
constructor
A new instance of XData.
-
#instructions ⇒ Object
- Get the Data Form instructions return
- Array
-
of [XDataInstructions] or nil.
-
#instructions=(i) ⇒ Object
- Add Data Form instructions i
-
[String].
-
#title ⇒ Object
- Get the Data Form title return
- XDataTitle
-
or nil.
-
#title=(title) ⇒ Object
- Set the Data Form title title
-
[String].
-
#type ⇒ Object
- Type of this Data Form result
-
:cancel * :form * :result * :submit * nil.
-
-
#type=(t) ⇒ Object
Set the type (see type).
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(type = nil) ⇒ XData
Returns a new instance of XData.
15 16 17 18 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 15 def initialize(type=nil) super() self.type = type end |
Instance Method Details
#field(var) ⇒ Object
Search a field by it’s var-name
- var
- String
- result
- XDataField
-
or [nil]
24 25 26 27 28 29 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 24 def field(var) each_element { |xe| return xe if xe.kind_of?(XDataField) and xe.var == var } nil end |
#fields(including_hidden = false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 31 def fields(including_hidden=false) fields = [] each_element do |xe| if xe.kind_of?(XDataField) and (including_hidden or (xe.type != :hidden and xe.type != :fixed)) fields << xe end end fields end |
#instructions ⇒ Object
Get the Data Form instructions
- return
- Array
-
of [XDataInstructions] or nil
89 90 91 92 93 94 95 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 89 def instructions fields = [] each_element('instructions') do |xe| fields << xe end fields end |
#instructions=(i) ⇒ Object
Add Data Form instructions
- i
- String
100 101 102 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 100 def instructions=(i) add(XDataInstructions.new(i)) end |
#title ⇒ Object
Get the Data Form title
- return
- XDataTitle
-
or nil
74 75 76 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 74 def title first_element('title') end |
#title=(title) ⇒ Object
Set the Data Form title
- title
- String
81 82 83 84 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 81 def title=(title) delete_elements('title') add_element(XDataTitle.new(title)) end |
#type ⇒ Object
Type of this Data Form
- result
-
:cancel
-
:form
-
:result
-
:submit
-
nil
-
49 50 51 52 53 54 55 56 57 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 49 def type case attributes['type'] when 'cancel' then :cancel when 'form' then :form when 'result' then :result when 'submit' then :submit else nil end end |
#type=(t) ⇒ Object
Set the type (see type)
61 62 63 64 65 66 67 68 69 |
# File 'lib/xmpp4r/dataforms/x/data.rb', line 61 def type=(t) case t when :cancel then attributes['type'] = 'cancel' when :form then attributes['type'] = 'form' when :result then attributes['type'] = 'result' when :submit then attributes['type'] = 'submit' else attributes['type'] = nil end end |