Sha256: 6902fdfaf67de5f7f534cd7c7169550bfadf47a537860fd30716931f6e34c446

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# Copyright (c) 2005 Assembla, Inc.
# MIT License

require 'uuidtools'

class UUID

  # Make an array of 64 URL-safe characters
  @@chars64=('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + ['-','_']
    #return a 22 byte URL-safe string, encoded six bits at a time using 64 characters
  def to_s22
  	integer=self.to_i
  	rval=''
    22.times do
      c=(integer & 0x3F)
      rval+=@@chars64[c]
      integer =integer >> 6
    end
    return rval.reverse
  end
  	# Create a new UUID from a 22char string
  def self.parse22(s)
    	# get the integer representation
    integer=0
    s.each_byte {|c|
    	integer = integer << 6
      pos=@@chars64.index(c.chr)
      integer+=pos
    }

    time_low = (integer >> 96) & 0xFFFFFFFF
    time_mid = (integer >> 80) & 0xFFFF
    time_hi_and_version = (integer >> 64) & 0xFFFF
    clock_seq_hi_and_reserved = (integer >> 56) & 0xFF
    clock_seq_low = (integer >> 48) & 0xFF
    nodes = []
    for i in 0..5 do
      nodes << ((integer >> (40 - (i * 8))) & 0xFF)
    end
    return new(time_low, time_mid, time_hi_and_version,
      clock_seq_hi_and_reserved, clock_seq_low, nodes)
  end	
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
parlement-0.10 vendor/plugins/guid/lib/uuid22.rb
parlement-0.3 vendor/plugins/guid/lib/uuid22.rb
parlement-0.4 vendor/plugins/guid/lib/uuid22.rb
parlement-0.5 vendor/plugins/guid/lib/uuid22.rb
parlement-0.6 vendor/plugins/guid/lib/uuid22.rb
parlement-0.7 vendor/plugins/guid/lib/uuid22.rb
parlement-0.8 vendor/plugins/guid/lib/uuid22.rb
parlement-0.9 vendor/plugins/guid/lib/uuid22.rb