Class: Metanorma::Plugin::Glossarist::DatasetRegistry
- Inherits:
-
Object
- Object
- Metanorma::Plugin::Glossarist::DatasetRegistry
- 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, bibliography, and dataset-level non-verbal entities (figures, tables, formulas). 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"- NON_VERBAL_KINDS =
Non-verbal entity kinds exposed by GlossaryStore. Each kind matches a method on
GlossaryStore(+#figures+,#tables,#formulas) that returns anArray<Figure|Table|Formula>, lazily loaded from{dataset_path}/{kind}/*.yaml. %i[figures tables formulas].freeze
Instance Method Summary collapse
-
#bibliography_for(context_name) ⇒ Object
Returns the BibliographyData for a registered context, or nil.
-
#concepts_at(path) ⇒ Object
Returns concepts cached at an absolute path.
- #context_path(key) ⇒ Object
- #find_concept(dataset_name, concept_name, document = nil) ⇒ Object
-
#initialize ⇒ DatasetRegistry
constructor
A new instance of DatasetRegistry.
-
#non_verbal_collection(context_name, kind) ⇒ Object
Returns the Array of dataset-level non-verbal entities of the given kind for a registered context (e.g.
Array<Glossarist::Figure>), ornilif the context isn't registered. -
#non_verbal_collections(context_name) ⇒ Object
Returns all available non-verbal collections for a context as a hash keyed by kind symbol (e.g.
{ figures: Array<Figure> }). - #register(document, contexts) ⇒ Object
-
#register_for(context_name) ⇒ Object
Returns the DatasetRegister for a registered context, or nil.
- #register_sections(context_name) ⇒ Object
- #resolve_dataset(document, dataset_name) ⇒ Object
Constructor Details
#initialize ⇒ DatasetRegistry
Returns a new instance of DatasetRegistry.
23 24 25 26 27 28 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 23 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).
76 77 78 79 80 81 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 76 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.
85 86 87 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 85 def concepts_at(path) store_for(path).concepts end |
#context_path(key) ⇒ Object
55 56 57 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 55 def context_path(key) @context_paths[key] end |
#find_concept(dataset_name, concept_name, document = nil) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 48 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 |
#non_verbal_collection(context_name, kind) ⇒ Object
Returns the Array of dataset-level non-verbal entities of the
given kind for a registered context (e.g. Array<Glossarist::Figure>),
or nil if the context isn't registered. Empty Array means the
dataset has no {kind}/ subdirectory.
kind must be one of NON_VERBAL_KINDS. The kind symbol is the
message sent to GlossaryStore — adding a new kind requires both
a GlossaryStore accessor and an entry here.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 97 def non_verbal_collection(context_name, kind) unless NON_VERBAL_KINDS.include?(kind) raise ArgumentError, "unknown non-verbal kind: #{kind.inspect}" end path = @context_paths[context_name] return nil unless path store_for(path).public_send(kind) end |
#non_verbal_collections(context_name) ⇒ Object
Returns all available non-verbal collections for a context as a
hash keyed by kind symbol (e.g. { figures: Array<Figure> }).
Kinds whose subdirectory doesn't exist are omitted. Convenient
for building a NonVerbalRenderer in one call.
118 119 120 121 122 123 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 118 def non_verbal_collections(context_name) NON_VERBAL_KINDS.each_with_object({}) do |kind, memo| collection = non_verbal_collection(context_name, kind) memo[kind] = collection if collection && !collection.empty? end end |
#register(document, contexts) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 30 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).
62 63 64 65 66 67 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 62 def register_for(context_name) path = @context_paths[context_name] return nil unless path register_at(path) end |
#register_sections(context_name) ⇒ Object
69 70 71 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 69 def register_sections(context_name) register_for(context_name)&.sections end |
#resolve_dataset(document, dataset_name) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 39 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 |