Created
July 24, 2013 08:59
-
-
Save franciscoj/6069028 to your computer and use it in GitHub Desktop.
Small ruby script to transform a CSV file into a VCF file.
This file contains hidden or 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
# Requires fastercsv and vpim gems to be installed | |
require 'rubygems' | |
require 'fastercsv' | |
require 'vpim/vcard' | |
card = Vpim::DirectoryInfo.create([Vpim::DirectoryInfo::Field.create('VERSION', '2.1')], 'VCARD') | |
FasterCSV.foreach('contactos.csv') do |row| | |
first_name = row[1] | |
last_name = row[3] | |
mobile = row[13] | |
general = row[14] | |
email = row[15] | |
Vpim::Vcard::Maker.make2(card) do |maker| | |
maker.name do |n| | |
n.given = first_name unless first_name.nil? | |
n.family = last_name unless last_name.nil? | |
end | |
maker.add_tel(mobile) { |t| t.location = 'mobile'; t.preferred = true } unless mobile.nil? | |
maker.add_tel(general) { |t| t.location = 'mobile'} unless general.nil? | |
maker.add_email email unless email.nil? | |
end | |
end | |
puts card | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment