lib/guillotine.rb
# Internal: Shortens a URL with a specific character set at a certain
# length.
#
# url     - String URL to shorten.
# length  - Optional Integer maximum length of the short code desired.
# charset - Optional Array of String characters which will be present in
#           short code.  eg. ['a', 'b', 'c', 'd', 'e', 'f']
#
# Returns an encoded String code for the URL.
Shortens a URL with a specific character set at a certain
length.

url     - String URL to shorten.
length  - Optional Integer maximum length of the short code desired.
charset - Optional Array of String characters which will be present in
short code.  eg.

Returns an encoded String code for the URL.
Shortens a URL with a specific character set at a certain length . url - String URL to shorten . length - Optional Integer maximum length of the short code desired . charset - Optional Array of String characters which will be present in short code . eg . Returns an encoded String code for the URL .
def shorten_fixed_charset(url, length, char_set)
      number = (Digest::MD5.hexdigest(url).to_i(16) % (char_set.size**length))
      code = ""
      while (number > 0)
        code =  code + char_set[number % char_set.size]
        number /= char_set.size
      end
      code
    end
def shorten_fixed_charset ( url , length , char_set ) number = ( Digest :: MD5 . hexdigest ( url ) . to_i ( 16 ) % ( char_set . size ** length ) ) code = "" while ( number > 0 ) code = code + char_set [ number % char_set . size ] number /= char_set . size end code end
Internal: Shortens a URL with a specific character set at a certain
length.
Internal : Shortens a URL with a specific character set at a certain length .
url
<not_specific>
length
<not_specific>
char_set
<not_specific>