Class: Metanorma::Plugin::Glossarist::DatasetRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/plugin/glossarist/dataset_registry.rb

Overview

Resolves, caches, and exposes dataset models for a document.

Single source of truth for everything the preprocessor needs from a glossarist dataset: concepts, section hierarchy, and bibliography. Each is exposed as the typed Glossarist model object so callers never poke at raw YAML hashes.

Constant Summary collapse

BIBLIOGRAPHY_FILENAME =
"bibliography.yaml"
REGISTER_FILENAME =
"register.yaml"

Instance Method Summary collapse

Constructor Details

#initializeDatasetRegistry

Returns a new instance of DatasetRegistry.



18
19
20
21
22
23
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 18

def initialize
  @stores = {}
  @registers = {}
  @bibliographies = {}
  @context_paths = {}
end

Instance Method Details

#bibliography_for(context_name) ⇒ Object

Returns the BibliographyData for a registered context, or nil. Exposed as the typed model so callers iterate entries via BibliographyEntry accessors (#id, #reference, #title, #link).



71
72
73
74
75
76
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 71

def bibliography_for(context_name)
  path = @context_paths[context_name]
  return nil unless path

  bibliography_at(path)
end

#concepts_at(path) ⇒ Object

Returns concepts cached at an absolute path. Used by Liquid blocks that receive a pre-resolved absolute path.



80
81
82
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 80

def concepts_at(path)
  store_for(path).concepts
end

#context_path(key) ⇒ Object



50
51
52
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 50

def context_path(key)
  @context_paths[key]
end

#find_concept(dataset_name, concept_name, document = nil) ⇒ Object



43
44
45
46
47
48
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 43

def find_concept(dataset_name, concept_name, document = nil)
  dataset = resolve_dataset(document, dataset_name)
  return unless dataset

  dataset.find { |concept| concept.default_designation == concept_name }
end

#register(document, contexts) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 25

def register(document, contexts)
  contexts.split(";").map do |context|
    context_name, file_path = context.split(":", 2).map(&:strip)
    path = relative_file_path(document, file_path)
    @context_paths[context_name] = path
    "#{context_name}=#{path}"
  end
end

#register_for(context_name) ⇒ Object

Returns the DatasetRegister for a registered context, or nil. The DatasetRegister is the single source of truth for section hierarchy and concept→section membership (cascading ancestors).



57
58
59
60
61
62
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 57

def register_for(context_name)
  path = @context_paths[context_name]
  return nil unless path

  register_at(path)
end

#register_sections(context_name) ⇒ Object



64
65
66
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 64

def register_sections(context_name)
  register_for(context_name)&.sections
end

#resolve_dataset(document, dataset_name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 34

def resolve_dataset(document, dataset_name)
  return concepts_for(dataset_name) if @context_paths.key?(dataset_name)

  path = relative_file_path(document, dataset_name) if document
  return unless path

  concepts_at(path)
end