Class: Jabber::Dataforms::XData

Inherits:
X show all
Defined in:
lib/xmpp4r/dataforms/x/data.rb

Overview

Data Forms (JEP-0004) implementation

Instance Method Summary collapse

Methods inherited from X

add_namespaceclass, import

Methods inherited from REXML::Element

#delete_elements, #first_element, #first_element_text, import, #import, #replace_element_text

Constructor Details

#initialize(type = nil) ⇒ XData

Returns a new instance of XData


13
14
15
16
17
# File 'lib/xmpp4r/dataforms/x/data.rb', line 13

def initialize(type=nil)
  super()
  add_namespace('jabber:x:data')
  self.type = type
end

Instance Method Details

#field(var) ⇒ Object

Search a field by it's var-name

var
String
result
XDataField

or [nil]


38
39
40
41
42
43
# File 'lib/xmpp4r/dataforms/x/data.rb', line 38

def field(var)
  each_element { |xe|
    return xe if xe.kind_of?(XDataField) and xe.var == var
  }
  nil
end

#typeObject

Type of this Data Form

result
  • :cancel

  • :form

  • :result

  • :submit

  • nil


52
53
54
55
56
57
58
59
60
# File 'lib/xmpp4r/dataforms/x/data.rb', line 52

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)


64
65
66
67
68
69
70
71
72
# File 'lib/xmpp4r/dataforms/x/data.rb', line 64

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

#typed_add(xe) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xmpp4r/dataforms/x/data.rb', line 19

def typed_add(xe)
  if xe.kind_of?(REXML::Element)
    case xe.name
      when 'instructions' then super XDataInstructions.new.import(xe)
      when 'title' then super XDataTitle.new.import(xe)
      when 'field' then super XDataField.new.import(xe)
      when 'reported' then super XDataReported.new.import(xe)
      #when 'item' then super XDataItem.new.import(xe)
      else super xe
    end
  else
    super xe
  end
end