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 =
Map of plural kind symbol → (collection class, subdirectory name). Adding a new non-verbal kind = adding one entry here. The accessor ‘kind_for` and loader are derived from this table.
{ figures: [::Glossarist::Collections::FigureCollection, "figures"], tables: [::Glossarist::Collections::TableCollection, "tables"], formulas: [::Glossarist::Collections::FormulaCollection, "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 typed NonVerbalCollection for a registered context (e.g. FigureCollection), or nil if the dataset has no such subdirectory.
-
#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: FigureCollection }).
- #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.
28 29 30 31 32 33 34 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 28 def initialize @stores = {} @registers = {} @bibliographies = {} @non_verbal = {} @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).
82 83 84 85 86 87 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 82 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.
91 92 93 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 91 def concepts_at(path) store_for(path).concepts end |
#context_path(key) ⇒ Object
61 62 63 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 61 def context_path(key) @context_paths[key] end |
#find_concept(dataset_name, concept_name, document = nil) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 54 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 typed NonVerbalCollection for a registered context (e.g. FigureCollection), or nil if the dataset has no such subdirectory. kind is one of the keys of NON_VERBAL_KINDS.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 98 def non_verbal_collection(context_name, kind) unless NON_VERBAL_KINDS.key?(kind) raise ArgumentError, "unknown non-verbal kind: #{kind.inspect}" end path = @context_paths[context_name] return nil unless path collection_class, subdir = NON_VERBAL_KINDS.fetch(kind) non_verbal_at(path, kind, subdir, collection_class) 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: FigureCollection }). Kinds whose subdirectory doesn’t exist are omitted. Convenient for building a NonVerbalRenderer in one call.
120 121 122 123 124 125 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 120 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 end end |
#register(document, contexts) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 36 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).
68 69 70 71 72 73 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 68 def register_for(context_name) path = @context_paths[context_name] return nil unless path register_at(path) end |
#register_sections(context_name) ⇒ Object
75 76 77 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 75 def register_sections(context_name) register_for(context_name)&.sections end |
#resolve_dataset(document, dataset_name) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/metanorma/plugin/glossarist/dataset_registry.rb', line 45 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 |