Module: XMLMotorEngine
- Defined in:
- lib/xml-motor/xml-motor-engine.rb
Class Method Summary collapse
- ._get_attrib_key_val_(attrib) ⇒ Object
- ._grab_my_attrib_(attrib_key, index_to_find, attrib_to_find = nil) ⇒ Object
- ._grab_my_node_(index_to_find, attrib_to_find = nil, with_tag = false) ⇒ Object
- ._indexify_(_nodes = nil) ⇒ Object
- ._splitter_(xmldata) ⇒ Object
- .pre_processed_content(_nodes, _tags = nil, tag_to_find = nil, attrib_to_find = nil, with_tag = false, just_attrib_val = nil) ⇒ Object
- .xml_extracter(tag_to_find = nil, attrib_to_find = nil, with_tag = false, just_attrib_val = nil) ⇒ Object
- .xml_miner(xmldata, tag_to_find = nil, attrib_to_find = nil, with_tag = false) ⇒ Object
- .xmlnodes(xml_nodes = nil) ⇒ Object
- .xmltags(xml_tags = nil) ⇒ Object
Class Method Details
._get_attrib_key_val_(attrib) ⇒ Object
46 47 48 49 50 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 46 def self._get_attrib_key_val_ (attrib) attrib_key = attrib.split(/=/)[0].strip attrib_val = attrib.split(/=/)[1..-1].join.strip [attrib_key, XMLUtils.dbqot_string(attrib_val)] end |
._grab_my_attrib_(attrib_key, index_to_find, attrib_to_find = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 88 def self._grab_my_attrib_ (attrib_key, index_to_find, attrib_to_find=nil) unless attrib_to_find.nil? or attrib_to_find.empty? attrib_keyval = [attrib_to_find].flatten.collect{|keyval| _get_attrib_key_val_ keyval } attrib_justkey = attrib_keyval.select{|attr| attr[1].empty?} attrib_justval = attrib_keyval.select{|attr| attr[0].empty?} attrib_keyval -= (attrib_justkey + attrib_justval) end attribs = [] node_count = index_to_find.size/2 - 1 0.upto node_count do |ncount| node_start = index_to_find[ncount*2] node_stop = index_to_find[ncount*2 +1] unless attrib_to_find.nil? or attrib_to_find.empty? next if @xmlnodes[node_start][0][1].nil? check_keyval = attrib_keyval.collect{|keyval| @xmlnodes[node_start][0][1][keyval.first] == keyval.last}.include? false check_key = attrib_justkey.collect{|key| @xmlnodes[node_start][0][1][key.first].nil? }.include? true check_val = attrib_justval.collect{|val| @xmlnodes[node_start][0][1].each_value.include? val[1] }.include? false next if check_keyval or check_key or check_val end unless @xmlnodes[node_start][0][1].nil? attribs[ncount] = @xmlnodes[node_start][0][1][attrib_key] unless @xmlnodes[node_start][0][1][attrib_key].nil? end end attribs.delete(nil) unless attrib_to_find.nil? attribs end |
._grab_my_node_(index_to_find, attrib_to_find = nil, with_tag = false) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 52 def self._grab_my_node_ (index_to_find, attrib_to_find=nil, with_tag=false) unless attrib_to_find.nil? or attrib_to_find.empty? attrib_keyval = [attrib_to_find].flatten.collect{|keyval| _get_attrib_key_val_ keyval } attrib_justkey = attrib_keyval.select{|attr| attr[1].empty?} attrib_justval = attrib_keyval.select{|attr| attr[0].empty?} attrib_keyval -= (attrib_justkey + attrib_justval) end nodes = [] node_count = index_to_find.size/2 - 1 0.upto node_count do |ncount| node_start = index_to_find[ncount*2] node_stop = index_to_find[ncount*2 +1] unless attrib_to_find.nil? or attrib_to_find.empty? next if @xmlnodes[node_start][0][1].nil? check_keyval = attrib_keyval.collect{|keyval| @xmlnodes[node_start][0][1][keyval.first] == keyval.last}.include? false check_key = attrib_justkey.collect{|key| @xmlnodes[node_start][0][1][key.first].nil? }.include? true check_val = attrib_justval.collect{|val| @xmlnodes[node_start][0][1].each_value.include? val[1] }.include? false next if check_keyval or check_key or check_val end nodes[ncount] ||= "" nodes[ncount] += @xmlnodes[node_start][1] unless @xmlnodes[node_start][1].nil? (node_start+1).upto (node_stop-1) do |node_idx| any_attrib ||= "" any_attrib = XMLJoiner.dejavu_attributes(@xmlnodes[node_idx][0][1]).to_s unless @xmlnodes[node_idx][0][1].nil? nodes[ncount] += "<" + @xmlnodes[node_idx][0][0] + any_attrib + ">" nodes[ncount] += @xmlnodes[node_idx][1] unless @xmlnodes[node_idx][1].nil? end if with_tag tagifyd = XMLJoiner.dejavu_node @xmlnodes[node_start][0] nodes[ncount] = tagifyd.first + nodes[ncount] + tagifyd.last end end nodes.delete(nil) unless attrib_to_find.nil? nodes end |
._indexify_(_nodes = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 19 def self._indexify_(_nodes=nil) xmlnodes _nodes unless _nodes.nil? @xmltags = {} idx = 1 depth = 0 @xmlnodes[1..-1].each do |xnode| tag_name = xnode[0][0].strip.downcase if tag_name.match(/^\/.*/) then depth -= 1 @xmltags[tag_name[1..-1]][depth] ||= [] @xmltags[tag_name[1..-1]][depth].push idx elsif tag_name.chomp.match(/^\/$/) then @xmltags[tag_name] ||= {} @xmltags[tag_name][depth] ||= [] @xmltags[tag_name][depth].push idx @xmltags[tag_name][depth].push idx else @xmltags[tag_name] ||= {} @xmltags[tag_name][depth] ||= [] @xmltags[tag_name][depth].push idx depth += 1 end idx +=1 end @xmltags end |
._splitter_(xmldata) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 2 def self._splitter_(xmldata) start_splits = xmldata.split(/</) @xmlnodes = [start_splits[0]] start_splits[1..-1].each do |val| tag_attr = XMLChopper.get_tag_attrib_value(val.gsub('/>','>')) if val.match(/\/>/) post_attr = tag_attr[1] tag_attr[1] = '' @xmlnodes.push tag_attr @xmlnodes.push [["/#{tag_attr[0][0]}", nil], post_attr] else @xmlnodes.push tag_attr end end @xmlnodes end |
.pre_processed_content(_nodes, _tags = nil, tag_to_find = nil, attrib_to_find = nil, with_tag = false, just_attrib_val = nil) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 147 def self.pre_processed_content(_nodes, =nil, tag_to_find=nil, attrib_to_find=nil, with_tag=false, just_attrib_val=nil) begin xmlnodes _nodes unless .nil? else _indexify_ end return xml_extracter tag_to_find, attrib_to_find, with_tag, just_attrib_val rescue XMLStdout._err "Parsing processed XML Nodes." end return nil end |
.xml_extracter(tag_to_find = nil, attrib_to_find = nil, with_tag = false, just_attrib_val = nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 116 def self.xml_extracter(tag_to_find=nil, attrib_to_find=nil, with_tag=false, just_attrib_val=nil) index_to_find = [] if attrib_to_find.nil? and tag_to_find.nil? return nil elsif tag_to_find.nil? index_to_find = @xmltags.collect {|xtag| xtag[1].collect {|val| val[1] }}.flatten else index_to_find = XMLIndexHandler.get_tag_indexes self, tag_to_find.downcase end if just_attrib_val.nil? return _grab_my_node_ index_to_find, attrib_to_find, with_tag else return _grab_my_attrib_ just_attrib_val, index_to_find, attrib_to_find end end |
.xml_miner(xmldata, tag_to_find = nil, attrib_to_find = nil, with_tag = false) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 132 def self.xml_miner(xmldata, tag_to_find=nil, attrib_to_find=nil, with_tag=false) return nil if xmldata.nil? _splitter_ xmldata _indexify_ xml_extracter tag_to_find, attrib_to_find, with_tag end |
.xmlnodes(xml_nodes = nil) ⇒ Object
139 140 141 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 139 def self.xmlnodes(xml_nodes=nil) @xmlnodes = xml_nodes || @xmlnodes end |
.xmltags(xml_tags = nil) ⇒ Object
143 144 145 |
# File 'lib/xml-motor/xml-motor-engine.rb', line 143 def self.(=nil) @xmltags = || @xmltags end |