Top Level Namespace
Defined Under Namespace
Modules: ConstraintClean
Instance Method Summary collapse
Instance Method Details
#cleanupConstraints(file) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/constraintClean.rb', line 4 def cleanupConstraints(file) f = File.open(file) doc = Nokogiri::XML(f) f.close excluded = doc.xpath('//exclude') included = doc.xpath('//include') result = [] excluded.each do |node| found = false for includedNode in included if node.attr('reference') == includedNode.attr('reference') found = true break end end if !found result.push(node) nodeID = node.attr('reference') constraints = doc.xpath("//constraint[@id='#{nodeID}']") result += constraints end end if result.count > 0 f1 = File.open(file, 'w') result.each{ |node| node.remove } f1.write(doc.to_xml) f1.close p "removed #{result.count} constraint(s) from #{file}" end end |