Skip to content

Instantly share code, notes, and snippets.

@rmm5t
Created December 7, 2008 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rmm5t/32998 to your computer and use it in GitHub Desktop.
Save rmm5t/32998 to your computer and use it in GitHub Desktop.
vCards -> Asterisk commands for improved caller id
#!/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
# Original regex idea from @coderifous's earlier revisions of http://gist.github.com/32529
ARGV.collect{ |f| open(f).readlines }.flatten.each do |line|
if line =~ /^FN:(.*)$/
$name = $1.chomp
elsif line =~ /^TEL;type=([A-Z]).*:(.+)$/ && (location, n = $1, $2)
formatted_number = (n.gsub!(/\D/, "") =~ /^1/) ? n[0...11] : "1#{n[0...10]}"
puts %(asterisk -rx 'database put cidname #{formatted_number} "#{$name} [#{location}]"'\n)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment