Class: DPN::Bagit::UUID4Validator
- Inherits:
-
Object
- Object
- DPN::Bagit::UUID4Validator
- Defined in:
- lib/dpn/bagit/uuidv4_validator.rb
Overview
A class that validates whether a string is a v4 UUID or not.
Instance Method Summary collapse
-
#initialize(dashes = nil) ⇒ UUID4Validator
constructor
Create a new validator.
-
#isValid?(uuid) ⇒ Boolean
Check if the given string is valid according to this validator.
Constructor Details
#initialize(dashes = nil) ⇒ UUID4Validator
Create a new validator.
9 10 11 12 13 14 15 16 17 |
# File 'lib/dpn/bagit/uuidv4_validator.rb', line 9 def initialize(dashes = nil) if dashes == nil @pattern = /^[A-Fa-f0-9]{8}-?[A-Fa-f0-9]{4}-?[A-Fa-f0-9]{4}-?[A-Fa-f0-9]{4}-?[A-Fa-f0-9]{12}\Z/ elsif dashes == true @pattern = /^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}\Z/ else @pattern = /^[A-Fa-f0-9]{8}[A-Fa-f0-9]{4}[A-Fa-f0-9]{4}[A-Fa-f0-9]{4}[A-Fa-f0-9]{12}\Z/ end end |
Instance Method Details
#isValid?(uuid) ⇒ Boolean
Check if the given string is valid according to this validator. This test is case-insensitive.
23 24 25 26 27 28 29 30 |
# File 'lib/dpn/bagit/uuidv4_validator.rb', line 23 def isValid?(uuid) if @pattern.match(uuid) #matches a v4 uuid, case-insensitive, with or without dashes. return true else return false end end |