module GnUUID

UUID version 5 with DNS|globalnames.org namespace

UUID version 5 with DNS|globalnames.org namespace

Constants

GN_NAMESPACE
VERSION

Public Class Methods

parse(obj) click to toggle source
# File lib/gn_uuid.rb, line 20
def parse(obj)
  str = obj.to_s.gsub(/\Aurn:uuid:/, "")
  str.gsub!(/[^0-9A-Fa-f]/, "")
  GnUUID::UUID.new([str[0..31]].pack("H*"))
end
uuid(str, guid = true) click to toggle source
# File lib/gn_uuid.rb, line 12
def uuid(str, guid = true)
  sha1 = Digest::SHA1.new
  sha1.update(GN_NAMESPACE)
  sha1.update(str)
  res = GnUUID::UUID.new(stamp_v5(sha1.digest[0..15]))
  guid ? res.to_s : res
end
version() click to toggle source
# File lib/gn_uuid/version.rb, line 7
def self.version
  VERSION
end

Private Class Methods

stamp_v5(str) click to toggle source
# File lib/gn_uuid.rb, line 28
def stamp_v5(str)
  str[6] = (str[6].ord & 0b1111 | 0b101_0000).chr
  str[8] = (str[8].ord & 0b11_1111 | 0b1000_0000).chr
  str
end