Created
April 2, 2012 01:25
-
-
Save Haroperi/2279905 to your computer and use it in GitHub Desktop.
Freshman list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
# | |
# input: | |
# Fullname [TAB] College [TAB] Prefecture [TAB] School code [TAB] School name | |
# | |
require 'CSV' | |
require 'pp' | |
require 'nkf' | |
def write_names(names, school) | |
return if names.size == 0 | |
print names.join("、") | |
print "(#{school})" | |
end | |
prev_pref = '' | |
prev_college = '' | |
prev_school = '' | |
prev_names = [] | |
name = '' | |
college = '' | |
pref = '' | |
school = '' | |
CSV.foreach(ARGV[0], col_sep: "\t") do |row| | |
# read one line | |
row.each_with_index { |e,i| row[i] = NKF.nkf('-Sw', e).sub(/\s+$/, '') } | |
name, college, pref, schoolcode, school = row | |
# school, students name | |
if prev_school == school | |
prev_names.push name | |
else | |
# output previous school and stsudents | |
write_names(prev_names, prev_school) | |
prev_names = [name] | |
prev_school = school | |
end | |
# prefecture | |
if prev_pref != pref | |
if prev_college != college | |
# next college | |
puts '' | |
puts '' | |
print college | |
end | |
puts "\n◆#{pref}" | |
end | |
prev_pref = pref | |
prev_college = college | |
end | |
# last school | |
write_names(prev_names, prev_school) | |
puts "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment