Class: UUID

Inherits:
Object
  • Object
show all
Defined in:
lib/imw/utils/uuid.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hex_to_str(str) ⇒ Object



19
20
21
# File 'lib/imw/utils/uuid.rb', line 19

def self.hex_to_str str
  /([\da-f]{8})([\da-f]{4})([\da-f]{4})([\da-f]{4})([\da-f]{12})/.match(str).captures.join '-'
end

.parse_hex(str) ⇒ Object



24
25
26
# File 'lib/imw/utils/uuid.rb', line 24

def self.parse_hex str
  parse(UUID.hex_to_str(str))
end

Instance Method Details

#hexdigestObject

Overrides UUIDTools – force 32 hex digits (leading zeros)



29
30
31
# File 'lib/imw/utils/uuid.rb', line 29

def hexdigest
  "%032x" % self.to_i
end

#to_pathObject

A string suitable for using as a path name –

Ex.

urn:uuid:3c0dce44-80a8-11dd-a897-001ff35a0a8b =>
urn_uuid/3c0dce44/80a8/11dd/a897/001ff35a0a8b

It’s well possible there are more perspicacious choices for points to split the string, but until we hit that limit this’ll do.



15
16
17
# File 'lib/imw/utils/uuid.rb', line 15

def to_path
  'urn_uuid/' + to_s.gsub(/[\:\-]/,'/')
end