Created
August 10, 2012 08:04
-
-
Save sorah/3312515 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
task :zip do | |
csv_path = Rails.root.join("config", "KEN_ALL.csv").to_s | |
unless File.exist?(csv_path) | |
abort "config/KEN_ALL.csv not exists." | |
end | |
puts "=> Loading KEN_ALL.csv" | |
a = File.read(csv_path).encode("UTF-8", "CP932").split(/\r?\n/) | |
dic = a.each_with_object({}) do |x, d| | |
next if /以下に掲載がない場合/ =~ x | |
t = x.scan(/^.+?,".+?","(.+?)",".+?",".+?",".+?","(.+?)","(.+?)","(.+?)"/).flatten | |
d[t.shift] = t.join.gsub(/(.+?)/,"") | |
end | |
puts "=> Marshalling" | |
marshal_path = Rails.root.join("config", "zipcode.marshal") | |
open(marshal_path, 'wb') do |io| | |
io.write Marshal.dump(dic) | |
end | |
puts "" | |
puts "Done: config/zipcode.marshal" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment