Skip to content

Instantly share code, notes, and snippets.

@moro
Created December 26, 2008 00:57
Show Gist options
  • Save moro/39985 to your computer and use it in GitHub Desktop.
Save moro/39985 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# vim:set fileencoding=utf-8 filetype=ruby
$KCODE = 'u'
require 'rubygems'
require 'csv'
require 'vpim/vcard'
data = Vpim::Vcard.decode(ARGF).map do |vcard|
next unless addr = vcard.address
full_addr = [addr.region, addr.locality, addr.street].map{|s| s.strip }.join(" ")
spouse = if line = vcard.lines("X-ABRELATEDNAMES").first
line.value
else
""
end
[vcard.name.fullname, spouse, addr.postalcode, full_addr]
end.compact
CSV.generate("/tmp/address.csv"){|writer| data.each{|row| writer << row } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment