Class: Glossarist::ConceptDocument

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/glossarist/concept_document.rb

Direct Known Subclasses

V2::ConceptDocument, V3::ConceptDocument

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_version(version) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/glossarist/concept_document.rb', line 24

def self.for_version(version)
  case version.to_s
  when "2"
    V2::ConceptDocument
  else
    V3::ConceptDocument
  end
end

.from_managed_concept(managed_concept) ⇒ Object



17
18
19
20
21
22
# File 'lib/glossarist/concept_document.rb', line 17

def self.from_managed_concept(managed_concept)
  new(
    concept: managed_concept,
    localizations: managed_concept.localizations&.values || [],
  )
end

Instance Method Details

#ensure_concept_uuid!Object

Set concept.uuid from the document's record key (+id+) when the YAML stream did not provide one. The YAML is the source of truth for the UUID; id is a layout concern — for the grouped layout it is the filename stem, which may be a clause identifier (e.g. 3.1.1.1.yaml) rather than a UUID. Both the load path (ConceptStore#load_glossary) and the round-trip path (ConceptDocumentSerializer#deserialize) call this so the rule lives in one place.



46
47
48
49
50
# File 'lib/glossarist/concept_document.rb', line 46

def ensure_concept_uuid!
  return unless concept && id

  concept.uuid ||= id
end

#to_managed_conceptObject



33
34
35
36
37
# File 'lib/glossarist/concept_document.rb', line 33

def to_managed_concept
  mc = concept
  localizations.each { |l10n| mc.add_localization(l10n) }
  mc
end