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

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

Class Method Summary collapse

Class Method Details

.parse(obj) ⇒ Object



18
19
20
21
22
# File 'lib/gn_uuid.rb', line 18

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



10
11
12
13
14
15
16
# File 'lib/gn_uuid.rb', line 10

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



5
6
7
# File 'lib/gn_uuid/version.rb', line 5

def self.version
  VERSION
end