Method: Scrubyt::ResultDumper.to_csv

Defined in:
lib/scrubyt/output/result_dumper.rb

.to_csv(pattern) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/scrubyt/output/result_dumper.rb', line 44

def self.to_csv(pattern)
  result = []
  flat_csv_inner = lambda {|e, parts|
    content = e.text || ''
    parts << content if ((e.is_a? REXML::Element) && content != '')
    e.children.each {|c| flat_csv_inner.call(c, parts) if c.is_a? REXML::Element }
    parts
  }
  to_xml(pattern).root.elements['/root'].each {|e| result << flat_csv_inner.call(e, []) }
  (result.map! {|a| a.join(',')}).join("\n")
end