Module: StompMessage::XmlHelper
- Included in:
- Message
- Defined in:
- lib/stomp_message/message.rb
Instance Method Summary collapse
-
#add_elements(top) ⇒ Object
add all elements to top variable.
- #create_element(element_name, element_value) ⇒ Object
-
#xml_instance_variable(iv_input) ⇒ Object
create elements from instance variables…
Instance Method Details
#add_elements(top) ⇒ Object
add all elements to top variable
42 43 44 45 46 47 48 49 50 |
# File 'lib/stomp_message/message.rb', line 42 def add_elements(top) elements = [] self.instance_variables.each {|iv| xml_instance_variable(iv).each {|x| elements << x} } elements.each {|e| top.add_element e} top end |
#create_element(element_name, element_value) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/stomp_message/message.rb', line 35 def create_element(element_name, element_value) # puts "in create element #{element_name}: #{element_value}" element_xml= REXML::Element.new element_name element_xml.text=element_value element_xml end |
#xml_instance_variable(iv_input) ⇒ Object
create elements from instance variables… (instance variablesneed to be set) array variables need to end in s (eg mssidns) and are handled recurvisely
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stomp_message/message.rb', line 11 def xml_instance_variable(iv_input) iv=iv_input.delete('@') class_var=eval("self.#{iv}.class") # puts "class is #{class_var} " iv_xml=[] case when class_var==Array #puts "in array with #{iv}" len=iv.size check_for_s=iv[len-1] # puts "iv #{iv}: len is #{len} last digit is #{check_for_s}" raise "not terminate in s or too short" if len <=1 or check_for_s!=115 the_array = eval("self.#{iv}") iv_short = iv[0..len-2] #puts "iv short is #{iv_short}" the_array.each {|e| iv_xml << create_element(iv_short,e) } else val= eval "self.#{iv}" iv_xml[0]= create_element(iv.to_s,val) end return iv_xml end |