Last active
August 29, 2015 13:57
-
-
Save masao/9383194 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# -*- coding: cp932 -*- | |
require "csv" | |
format = :faculty | |
if ARGV and ARGV[0] == "-page" | |
format = :page | |
ARGV.shift | |
end | |
filename = ARGV[ 0 ] || "KLIS_List_20140309.csv" | |
def index_yomi( str ) | |
yomi = case str | |
when /\A医療/ | |
"イ" | |
when /\A学/ | |
"カ" | |
when /\A(基礎|教育)/ | |
"キ" | |
when /\A経営/ | |
"ケ" | |
when /\A(公共|国際)/ | |
"コ" | |
when /\A(自然|質|生涯|情報)/ | |
"シ" | |
when /\A(生命|専門)/ | |
"セ" | |
when /\A卒業/ | |
"ソ" | |
when /\A多/ | |
"タ" | |
when /\A(知|中国)/ | |
"チ" | |
when /\A哲学/ | |
"テ" | |
when /\A(統計|読書|図書館|特許)/ | |
"ト" | |
when /\A日本/ | |
"ニ" | |
when /\A量/ | |
"リ" | |
else | |
str[ 0, 2 ] | |
end | |
[ yomi, str ] | |
end | |
result = {} | |
results = [] | |
CSV.open( filename, "r" ) do |data| | |
num, name, degree, std_year, semester, wday, room, faculty, description, note, page, = data | |
next if faculty.nil? or faculty == "担当教員" | |
if format == :page | |
results << [ name, page ] | |
else | |
faculty.split( /\r?\n/ ).each do |f| | |
result[ f ] ||= [] | |
result[ f ] << name | |
end | |
end | |
end | |
if format == :page | |
results.sort_by{|e| index_yomi( e.first ) }.each do |e| | |
puts e.join( "\t" ) | |
end | |
else | |
result.each do |k, v| | |
puts [ k, *v ].join( "\t" ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment