Created
December 5, 2008 22:11
-
-
Save coderifous/32529 to your computer and use it in GitHub Desktop.
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
#!/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