Created
December 7, 2008 00:32
-
-
Save rmm5t/32998 to your computer and use it in GitHub Desktop.
vCards -> Asterisk commands for improved caller id
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 | |
# 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