Class: InferModel::Parsers::UUID

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer, Callable
Defined in:
lib/infer_model/parsers/uuid.rb

Constant Summary collapse

UUID_REGEX =
/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i

Instance Method Summary collapse

Instance Method Details

#callObject

Raises:



13
14
15
16
17
18
19
# File 'lib/infer_model/parsers/uuid.rb', line 13

def call
  raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank
  return if value.nil? || value.empty?
  return value if UUID_REGEX.match?(value)

  raise Parsers::Error, "'#{value}' is not a UUID"
end