Class: Suma::Urn

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/urn.rb

Overview

Value object encapsulating URN semantics for ISO 10303 datasets.

Normalises a URN prefix (stripping any trailing wildcard :*) and provides factory methods for composing leaf URNs:

  • #for_schema(id)<base>:tech:<id>
  • #for_term(id)<base>:term:<id>
  • #for_entity(ref)<base>:tech:<ref>

The wildcard form is preserved via #wildcard and #aliases so callers can populate urnAliases in register.yaml without re-implementing the normalisation logic.

Constant Summary collapse

WILDCARD_SUFFIX =
":*"
TECH_COMPONENT =
"tech"
TERM_COMPONENT =
"term"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Urn

Returns a new instance of Urn.



23
24
25
# File 'lib/suma/urn.rb', line 23

def initialize(raw)
  @base = strip_wildcard(raw.to_s)
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



21
22
23
# File 'lib/suma/urn.rb', line 21

def base
  @base
end

Instance Method Details

#aliasesObject



35
36
37
# File 'lib/suma/urn.rb', line 35

def aliases
  [wildcard]
end

#for_entity(full_ref) ⇒ Object



47
48
49
# File 'lib/suma/urn.rb', line 47

def for_entity(full_ref)
  compose(TECH_COMPONENT, full_ref)
end

#for_schema(schema_id) ⇒ Object



39
40
41
# File 'lib/suma/urn.rb', line 39

def for_schema(schema_id)
  compose(TECH_COMPONENT, schema_id)
end

#for_term(concept_identifier) ⇒ Object



43
44
45
# File 'lib/suma/urn.rb', line 43

def for_term(concept_identifier)
  compose(TERM_COMPONENT, concept_identifier)
end

#to_sObject



27
28
29
# File 'lib/suma/urn.rb', line 27

def to_s
  base
end

#wildcardObject



31
32
33
# File 'lib/suma/urn.rb', line 31

def wildcard
  "#{base}#{WILDCARD_SUFFIX}"
end