Class: RbEAI::Xml2CsvScript
- Defined in:
- lib/rbeai/TransfLogic.rb
Instance Method Summary collapse
- #doTransform(file, newfilename) ⇒ Object
-
#initialize(node) ⇒ Xml2CsvScript
constructor
A new instance of Xml2CsvScript.
Methods inherited from Script
Constructor Details
#initialize(node) ⇒ Xml2CsvScript
Returns a new instance of Xml2CsvScript.
120 121 122 123 124 125 |
# File 'lib/rbeai/TransfLogic.rb', line 120 def initialize(node) super(node) @xprow = node.attributes["xprow"] @xpitem = node.attributes["xpitem"] @separator = (sep = node.attributes["separator"])!= nil ? sep : "\t" end |
Instance Method Details
#doTransform(file, newfilename) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rbeai/TransfLogic.rb', line 127 def doTransform(file, newfilename) csvarr = [] xmlDoc = Document.new(File.new(file)) XPath.each(xmlDoc, "#{@xprow}") do |el| csvline = "" bsep = false XPath.each(el, "#{@xpitem}") do |el2| csvline << @separator if bsep csvline << el2.to_s bsep = true end csvarr << csvline end rio("#{newfilename}").puts!(csvarr) end |