Class: Suma::Urn
- Inherits:
-
Object
- Object
- Suma::Urn
- 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
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Instance Method Summary collapse
- #aliases ⇒ Object
- #for_entity(full_ref) ⇒ Object
- #for_schema(schema_id) ⇒ Object
- #for_term(concept_identifier) ⇒ Object
-
#initialize(raw) ⇒ Urn
constructor
A new instance of Urn.
- #to_s ⇒ Object
- #wildcard ⇒ Object
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
#base ⇒ Object (readonly)
Returns the value of attribute base.
21 22 23 |
# File 'lib/suma/urn.rb', line 21 def base @base end |
Instance Method Details
#aliases ⇒ Object
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_s ⇒ Object
27 28 29 |
# File 'lib/suma/urn.rb', line 27 def to_s base end |
#wildcard ⇒ Object
31 32 33 |
# File 'lib/suma/urn.rb', line 31 def wildcard "#{base}#{WILDCARD_SUFFIX}" end |