Module: Opencdd::GUID
- Defined in:
- lib/opencdd/guid.rb
Constant Summary collapse
- PATTERN =
/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i.freeze
Class Method Summary collapse
Class Method Details
.generate ⇒ Object
9 10 11 |
# File 'lib/opencdd/guid.rb', line 9 def self.generate SecureRandom.uuid end |
.set_on(entity) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/opencdd/guid.rb', line 18 def self.set_on(entity) guid = generate # Use the field-access seam so writes go through canonical-id # resolution. Keeps GUID writes consistent with reads and # avoids bypassing the Field DSL. entity.write_property!(Opencdd::PropertyIds::MDC_P066, guid) guid end |
.valid?(value) ⇒ Boolean
13 14 15 16 |
# File 'lib/opencdd/guid.rb', line 13 def self.valid?(value) return false unless value.is_a?(String) PATTERN.match?(value) end |