Class: AgentXmpp::Xmpp::XDataField

Inherits:
Element 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(var = nil, type = nil) ⇒ XDataField

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



264
265
266
267
268
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 264

def initialize(var=nil, type=nil)
  super()
  self.var = var if var
  self.type = type if type
end

Instance Method Details

#optionsObject

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



295
296
297
298
299
300
301
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 295

def options
  elements.inject('option',{}) do |r, e|
    value = nil
    value = (ve = first_element('value')).nil? ? nil : ve.text
    r[value] = e.attributes['label'] if value; r 
  end
end

#options=(opts) ⇒ Object

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



304
305
306
307
308
309
310
311
312
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 304

def options=(opts)
  opts = opts.inject({}){|h,v| h.update(v => v.to_s.gsub(/_/,' '))} if opts.kind_of?(Array)
  delete_elements('option')
  opts.each do |value,label|
    o = add(REXML::Element.new('option'))
    o.attributes['label'] = label
    o.add(REXML::Element.new('value')).text = value.to_s
  end
end

#required=(r) ⇒ Object

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



278
279
280
281
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 278

def required=(r)
  delete_elements('required')
  add REXML::Element.new('required') if r
end

#required?Boolean

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

Returns:

  • (Boolean)


271
272
273
274
275
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 271

def required?
  res = false
  each_element('required') { res = true }
  res
end

#valuesObject

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



284
285
286
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 284

def values
  elements.inject('value', []){|r,v| r << v.text}
end

#values=(ary) ⇒ Object

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



289
290
291
292
# File 'lib/agent_xmpp/xmpp/x_data.rb', line 289

def values=(ary)
  delete_elements('value')
  [ary].flatten.each {|v| add(REXML::Element.new('value')).text = v}
end