Skip to content

Instantly share code, notes, and snippets.

@Koronen
Created May 30, 2013 09:25
Show Gist options
  • Save Koronen/5676746 to your computer and use it in GitHub Desktop.
Save Koronen/5676746 to your computer and use it in GitHub Desktop.
A quick hack to convert a CSV table filled with contact details into a vCard.
#!/usr/bin/env ruby
require 'csv'
require 'erb'
def main
vcard_template = ERB.new(DATA.read)
CSV.parse(STDIN, headers: true).each do |row|
name = row['Namn']
email = row['Email']
skype = row['Skype']
phone = "+46" + row['Telefonnummer'].gsub(/[ -]/, '')[1..-1]
bday = Date.parse(row['Personnummer'][0..-5]).strftime
puts vcard_template.result(binding)
end
end
main if $0 == __FILE__
__END__
BEGIN:VCARD
VERSION:3.0
FN:<%= name %>
EMAIL;TYPE=INTERNET:<%= email %>
X-SKYPE:<%= skype %>
TEL;TYPE=CELL:<%= phone %>
BDAY:<%= bday %>
END:VCARD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment