Class: MacAdmin::Common::UUID

Inherits:
String
  • Object
show all
Defined in:
lib/macadmin/common.rb

Overview

Class for creating and checking UUID strings

Constant Summary collapse

UUID_REGEX =

897A6343-628F-4964-80F1-C86D0FFA3F91

'([A-Z0-9]{8})-([A-Z0-9]{4}-){3}([A-Z0-9]{12})'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUUID

Create a new UUID string



19
20
21
22
# File 'lib/macadmin/common.rb', line 19

def initialize
  uuid = %x{/usr/bin/uuidgen}.chomp
  super(uuid)
end

Class Method Details

.match(string, options = nil) ⇒ Object

Matches any string containing a UUID

  • returns Boolean



29
30
31
# File 'lib/macadmin/common.rb', line 29

def match(string, options = nil)
  string =~ Regexp.new(UUID_REGEX, options) ? $& : false
end

.valid?(uuid, options = nil) ⇒ Boolean

Validates the format of a UUID string

  • only true is the entire string is a UUID match

  • returns Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/macadmin/common.rb', line 36

def valid?(uuid, options = nil)
  strictlyuuid = '^' + UUID_REGEX + '$'
  uuid =~ Regexp.new(strictlyuuid, options) ? true : false
end