Class: AgentXmpp::Xmpp::XData

Inherits:
X show all
Defined in:
lib/agent_xmpp/xmpp/x_data.rb

Overview


Instance Method Summary collapse

Methods inherited from Element

#<<, class_for_name_xmlns, #clone, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=, xmpp_attribute, xmpp_child

Methods inherited from REXML::Element

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

Constructor Details

#initialize(type = nil) ⇒ XData

.….….….….….….….….….….….….….….….….….….….….….….….….….



34
35
36
37
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 34

def initialize(type=nil)
  super()
  self.type = type
end

Instance Method Details

#add_boolean(var, label = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



111
112
113
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 111

def add_boolean(var, label=nil)
  add_field(var, label, 'boolean')
end

#add_field_with_value(var, value, type = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



125
126
127
128
129
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 125

def add_field_with_value(var, value, type=nil)
  field = XDataField.new(var, type)
  field.values = value
  self << field
end

#add_fixed(val = ' ') ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



81
82
83
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 81

def add_fixed(val=' ')
  add_field_with_value(nil, val, 'fixed')
end

#add_hidden(var, val) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



86
87
88
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 86

def add_hidden(var, val)
  add_field_with_value(var, val, 'hidden')
end

#add_instructions(i) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



76
77
78
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 76

def add_instructions(i)
  add(XDataInstructions.new(i))
end

#add_jid_single(var, label = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



106
107
108
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 106

def add_jid_single(var, label=nil)
  add_field(var, label, 'jid-single')
end

#add_list_single(var, opts, label = nil, default = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



116
117
118
119
120
121
122
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 116

def add_list_single(var, opts, label=nil, default=nil)
  field = XDataField.new(var, 'list-single')
  field.label = label if label
  field.options = opts
  field.values = [default] if default
  self << field
end

#add_text_multi(var, label = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



96
97
98
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 96

def add_text_multi(var, label=nil)
  add_field(var, label, 'text-multi')
end

#add_text_private(var, label = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



101
102
103
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 101

def add_text_private(var, label=nil)
  add_field(var, label, 'text-private')
end

#add_text_single(var, label = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



91
92
93
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 91

def add_text_single(var, label=nil)
  add_field(var, label, 'text-single')
end

#add_title(title) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



65
66
67
68
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 65

def add_title(title)
  delete_elements('title')
  add_element(XDataTitle.new(title))
end

#fieldsObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



40
41
42
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 40

def fields
  elements.to_a('field')
end

#instructionsObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



71
72
73
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 71

def instructions
  elements.inject('instructions', []) {|f, xe| f << xe}
end

#itemsObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



45
46
47
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 45

def items
  elements.to_a('item')
end

#titleObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



60
61
62
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 60

def title
  first_element('title')
end

#to_nativeObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 132

def to_native 
  f, i = fields, items   
  if f.length.eql?(1) and i.length.eql?(0)
    to_scalar(f.first.values)
  elsif f.length > 1 and i.length.eql?(0)  
    to_hash(f)
  elsif i.length > 0 
     to_array_of_hashes(i)
  else
    nil
  end
end

#to_paramsObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



146
147
148
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 146

def to_params
  to_hash(fields)
end

#to_x_dataObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



151
152
153
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 151

def to_x_data
  self
end

#typeObject

.….….….….….….….….….….….….….….….….….….….….….….….….….



50
51
52
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 50

def type
  attributes['type'].to_sym
end

#type=(t) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….



55
56
57
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 55

def type=(t)
  attributes['type'] = t.to_s
end