Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'fastercsv'
- FasterCSV.open("tubbs.csv", "w") do |csv|
- File.open('tubbs.txt', "r") do |infile|
- while (line = infile.gets)
- if line=~/^(\d+.\s+\w+ \w+:)/
- fields = line.split('.')
- number = fields[0].strip
- name_and_categories=fields[1].strip.split(/:\s*/)
- fname, lname = name_and_categories[0].split
- cool = fields[name_and_categories[2] ? 2 : 3].split(/,\s+/)[0].strip.downcase
- cats = name_and_categories[1].split(/\/\s*/).map{|s| s.strip}
- rank = (name_and_categories[2] || fields[2]).strip
- csv << [number, fname, lname, cool, rank, *cats]
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment