Created
October 6, 2011 21:07
-
-
Save noeticpenguin/1268675 to your computer and use it in GitHub Desktop.
Salesforce 15 to 18 digit guid conversion
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 convert_guid(short_guid) | |
chunks = short_guid.chars.to_a | |
char_map = %w{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5} | |
extension = [] | |
chunks.each_slice(5) { |x| y = x.reverse.map {|c| (c.match /[A-Z]/) ? 1 : 0 }.join("").to_i(2) ; extension << y} | |
short_guid + (extension.map {|e| char_map.at(e)}).join("").to_s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment