Module: StompMessage::XmlHelper
- Included in:
- Message
- Defined in:
- lib/stomp_message/message.rb
Overview
help build xml commands from messages
Instance Method Summary collapse
-
#add_elements(top) ⇒ Object
add all elements to top variable.
- #create_element(element_name, element_value) ⇒ Object
- #load_instance_variables(xml_string) ⇒ Object
- #load_iv(iv_input, doc) ⇒ 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
117 118 119 120 121 122 123 124 125 |
# File 'lib/stomp_message/message.rb', line 117 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
99 100 101 102 103 104 |
# File 'lib/stomp_message/message.rb', line 99 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 |
#load_instance_variables(xml_string) ⇒ Object
111 112 113 114 115 |
# File 'lib/stomp_message/message.rb', line 111 def load_instance_variables(xml_string) xml_doc=REXML::Document.new(xml_string) self.instance_variables.each {|iv| load_iv(iv,xml_doc) } end |
#load_iv(iv_input, doc) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/stomp_message/message.rb', line 105 def load_iv(iv_input,doc) iv=iv_input.delete('@') val = REXML::XPath.first(doc, "//#{iv}").text puts "in load iv #{iv} and val: #{val}" eval "self.#{iv}=#{val}" 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/stomp_message/message.rb', line 75 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 |