Module: GnUUID

Defined in:
lib/gn_uuid.rb,
lib/gn_uuid/uuid.rb,
lib/gn_uuid/version.rb

Overview

UUID version 5 with DNS|globalnames.org namespace

Defined Under Namespace

Classes: UUID

Constant Summary collapse

GN_NAMESPACE =
"\x90\x18\x11\x96\xFE\xCFP\x82\xA4\xC1A\x1DO1L\xDA"
VERSION =
"0.5.1"

Class Method Summary collapse

Class Method Details

.parse(obj) ⇒ Object



20
21
22
23
24
# 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) ⇒ Object



12
13
14
15
16
17
18
# 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

.versionObject



7
8
9
# File 'lib/gn_uuid/version.rb', line 7

def self.version
  VERSION
end