Sha256: 9077a4a81314339823e31adb6e029f19b934cfa1e04bb83dd454101f59db71cf

Contents?: true

Size: 722 Bytes

Versions: 21

Compression:

Stored size: 722 Bytes

Contents

require 'uuidtools'

class UUID

  #
  # 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.
  #
  def to_path
    'urn_uuid/' + to_s.gsub(/[\:\-]/,'/')
  end

  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


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

  # Overrides UUIDTools -- force 32 hex digits (leading zeros)
  def hexdigest
    "%032x" % self.to_i
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
imw-0.2.18 lib/imw/utils/uuid.rb
imw-0.2.17 lib/imw/utils/uuid.rb
imw-0.2.16 lib/imw/utils/uuid.rb
imw-0.2.15 lib/imw/utils/uuid.rb
imw-0.2.14 lib/imw/utils/uuid.rb
imw-0.2.13 lib/imw/utils/uuid.rb
imw-0.2.12 lib/imw/utils/uuid.rb
imw-0.2.11 lib/imw/utils/uuid.rb
imw-0.2.10 lib/imw/utils/uuid.rb
imw-0.2.9 lib/imw/utils/uuid.rb
imw-0.2.8 lib/imw/utils/uuid.rb
imw-0.2.7 lib/imw/utils/uuid.rb
imw-0.2.6 lib/imw/utils/uuid.rb
imw-0.2.5 lib/imw/utils/uuid.rb
imw-0.2.4 lib/imw/utils/uuid.rb
imw-0.2.3 lib/imw/utils/uuid.rb
imw-0.2.2 lib/imw/utils/uuid.rb
imw-0.2.1 lib/imw/utils/uuid.rb
imw-0.2.0 lib/imw/utils/uuid.rb
imw-0.1.1 lib/imw/utils/uuid.rb