Posted By

bsrinivasan92 on 01/31/12


Tagged


Versions (?)

xml_creator.rb


 / Published in: Ruby
 

xml creator

  1. require "rexml/document"
  2. include REXML
  3. Dir.chdir("./docs")
  4.  
  5. outf=File.new("../graphs/GRAPH.xml",'w')
  6.  
  7. data=Hash.new
  8.  
  9. Dir['*.xml'].each do |filename|
  10. doc=Document.new File.new(filename)
  11. as=XPath.first(doc, "//assignees/assignee/addressbook/orgname")
  12. if as
  13. assignee=as.text
  14. else
  15. assignee="NO_ASSIGNEE"
  16. end
  17. puts "#{filename}---#{assignee}"
  18. if data[assignee]
  19. data[assignee]=data[assignee]+1
  20. else
  21. data[assignee]=1
  22. end
  23. end
  24.  
  25. barfile=File.open("../graphs/bar.xml")
  26. bars=barfile.readlines
  27.  
  28. filestr=''
  29.  
  30. #clean data
  31. data.delete("NO_ASSIGNEE")
  32. #==========
  33. data.each { |assignee,count|
  34. filestr=filestr+"<point name=\"#{assignee}\" y=\"#{count}\"/>" if count>4
  35. }
  36. bars[-6]=filestr
  37.  
  38. bars.each do |line|
  39. outf.puts line
  40. end

Report this snippet  

You need to login to post a comment.