Skip to content

Instantly share code, notes, and snippets.

@jlecour
Created September 28, 2010 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlecour/600590 to your computer and use it in GitHub Desktop.
Save jlecour/600590 to your computer and use it in GitHub Desktop.
def self.native_id_to_int(native_id)
alpha = "-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
res = ""
i = 0
native_id.split(//).each do |c|
if ((i+=1) <= 4) && alpha.include?(c.to_s)
index = alpha.index(c) + 10
res += index.to_s
else
res += c
end
end
res
end
def self.id_to_native_id(id)
id = id.to_s
alpha = "-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
res = ""
i = id[0,2].to_i - 10
res += alpha[i,1]
i = id[2,2].to_i - 10
res += alpha[i,1]
i = id[4,2].to_i - 10
res += alpha[i,1]
i = id[6,2].to_i - 10
res += alpha[i,1]
res += id[8,(id.length-8)]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment