Class: MacAdmin::Common::UUID
- Inherits:
-
String
- Object
- String
- MacAdmin::Common::UUID
- 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
-
.match(string, options = nil) ⇒ Object
Matches any string containing a UUID - returns Boolean.
-
.valid?(uuid, options = nil) ⇒ Boolean
Validates the format of a UUID string - only true is the entire string is a UUID match - returns Boolean.
Instance Method Summary collapse
-
#initialize ⇒ UUID
constructor
Create a new UUID string.
Constructor Details
#initialize ⇒ UUID
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, = nil) string =~ Regexp.new(UUID_REGEX, ) ? $& : 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
36 37 38 39 |
# File 'lib/macadmin/common.rb', line 36 def valid?(uuid, = nil) strictlyuuid = '^' + UUID_REGEX + '$' uuid =~ Regexp.new(strictlyuuid, ) ? true : false end |