Skip to content

Instantly share code, notes, and snippets.

@sorah
Created August 10, 2012 08:04
Show Gist options
  • Save sorah/3312515 to your computer and use it in GitHub Desktop.
Save sorah/3312515 to your computer and use it in GitHub Desktop.
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