module UuidShortner::GuidDecoder

Public Instance Methods

stretch(short_uuid) click to toggle source
# File lib/uuid_shortner/guid_decoder.rb, line 3
def stretch short_uuid
        guid_as_int = bijective_decode short_uuid
       guid_as_hex = guid_as_int.to_s(16)
       insert_uuid_hyphens guid_as_hex
end

Private Instance Methods

bijective_decode(s) click to toggle source
# File lib/uuid_shortner/guid_decoder.rb, line 14
def bijective_decode(s)
        # based on base2dec() in Tcl translation
        # at http://rosettacode.org/wiki/Non-decimal_radices/Convert#Ruby
        i = 0
        base = UuidShortner.ALPHABET.length
        s.each_char { |c|  i = i * base + UuidShortner.ALPHABET.index(c) }
        i
end
insert_uuid_hyphens(compact_guid) click to toggle source
# File lib/uuid_shortner/guid_decoder.rb, line 10
def insert_uuid_hyphens compact_guid
        guid = compact_guid.rjust(32,'0')
        "#{guid[0..7]}-#{guid[8..11]}-#{guid[12..15]}-#{guid[16..19]}-#{guid[20..31]}"
end