Created
March 31, 2011 13:18
-
-
Save Electron-libre/896314 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
def self.resolve(cdr) | |
prefixes_array = Array.new | |
cdr.called_number.each_char do |char| | |
prefixes_array << (prefixes_array[-1] or '') + char | |
end | |
prefixes_array.reverse! | |
best_match = Proc.new do |destinations, prefixes| | |
result = nil | |
while result == nil && prefixes != [] do | |
prefix = prefixes.shift | |
destinations.each do |entry| | |
result = entry.reload if entry.prefixes.include?(prefix) | |
end | |
end | |
result | |
end | |
destination = best_match.call( | |
Destination.only(:prefixes).where(:for_vno => cdr.deployment_id).any_in(:prefixes => prefixes_array).entries, | |
prefixes_array.dup | |
) | |
if destination == nil | |
destination = best_match.call( | |
Destination.only(:prefixes).where(:for_vno => nil).any_in(:prefixes => prefixes_array).entries, | |
prefixes_array.dup | |
) | |
end | |
return destination | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def self.resolve(cdr)
end