Created
May 30, 2013 09:25
-
-
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.
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 | |
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