Guest User

Untitled

a guest
Jul 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'rubygems'
  2. require 'fastercsv'
  3.  
  4. FasterCSV.open("tubbs.csv", "w") do |csv|
  5. File.open('tubbs.txt', "r") do |infile|
  6. while (line = infile.gets)
  7. if line=~/^(\d+.\s+\w+ \w+:)/
  8. fields = line.split('.')
  9. number = fields[0].strip
  10. name_and_categories=fields[1].strip.split(/:\s*/)
  11. fname, lname = name_and_categories[0].split
  12. cool = fields[name_and_categories[2] ? 2 : 3].split(/,\s+/)[0].strip.downcase
  13. cats = name_and_categories[1].split(/\/\s*/).map{|s| s.strip}
  14. rank = (name_and_categories[2] || fields[2]).strip
  15. csv << [number, fname, lname, cool, rank, *cats]
  16. end
  17. end
  18. end
  19. end
Add Comment
Please, Sign In to add comment