Skip to content

Instantly share code, notes, and snippets.

@coderifous
Created December 5, 2008 22:11
Show Gist options
  • Save coderifous/32529 to your computer and use it in GitHub Desktop.
Save coderifous/32529 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# usage: ruby vcard_skidoosh.rb vcard.vcf
# outputs a bunch of asterisk commands to stdout.
# taste it.
# Cargo culters: look elsewhere for best practices and good coding principles
# Ripped from @rmm5t http://gist.github.com/32998
def format_number(n)
n = n.gsub(/\D/, '')[0...11]
n.size == 10 ? "1" + n : n
end
ARGV.collect{ |f| open(f).readlines }.flatten.each do |line|
if line =~ /^FN:(.*)$/
$name = $1.chomp
elsif line =~ /^TEL;type=([A-Z]).*:(.+)$/
puts %Q(asterisk -rx 'database put cidname #{format_number($2)} "#{$name} [#{$1}]"'\n)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment