Class: Glossarist::GlossaryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/glossary_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlossaryStore

Returns a new instance of GlossaryStore.



7
8
9
10
11
12
13
14
15
16
# File 'lib/glossarist/glossary_store.rb', line 7

def initialize
  @package = nil
  @concept_document_class = V3::ConceptDocument
  @v1_concepts = nil
  @localized_concepts_dir_name = nil
  @dataset_path = nil
  @figures = nil
  @tables = nil
  @formulas = nil
end

Instance Attribute Details

#localized_concepts_dir_nameObject (readonly)

Returns the value of attribute localized_concepts_dir_name.



5
6
7
# File 'lib/glossarist/glossary_store.rb', line 5

def localized_concepts_dir_name
  @localized_concepts_dir_name
end

#packageObject (readonly)

Returns the value of attribute package.



5
6
7
# File 'lib/glossarist/glossary_store.rb', line 5

def package
  @package
end

Instance Method Details

#add_concept(managed_concept) ⇒ Object



112
113
114
115
116
117
# File 'lib/glossarist/glossary_store.rb', line 112

def add_concept(managed_concept)
  ensure_package
  doc = @concept_document_class.from_managed_concept(managed_concept)
  doc.id = managed_concept.uuid
  @package.add_model(doc)
end

#add_image(path, content) ⇒ Object



174
175
176
177
# File 'lib/glossarist/glossary_store.rb', line 174

def add_image(path, content)
  ensure_package
  @package.add_asset(path, content)
end

#bibliographyObject

── Bibliography ──



157
158
159
# File 'lib/glossarist/glossary_store.rb', line 157

def bibliography
  @package.models_for(BibliographyData).first
end

#bibliography=(value) ⇒ Object



161
162
163
164
165
166
# File 'lib/glossarist/glossary_store.rb', line 161

def bibliography=(value)
  ensure_package
  existing = bibliography
  @package.remove_model(BibliographyData, existing.shortname) if existing
  @package.add_model(value)
end

#build_metadata(shortname:, version:, **opts) ⇒ Object

── Convenience ──



213
214
215
216
217
218
219
# File 'lib/glossarist/glossary_store.rb', line 213

def (shortname:, version:, **opts)
  GcrMetadata.from_concepts(concepts, register_data: register_data, options: {
                              shortname: shortname,
                              version: version,
                              **opts,
                            })
end

#concept(uuid) ⇒ Object



107
108
109
110
# File 'lib/glossarist/glossary_store.rb', line 107

def concept(uuid)
  doc = @package.fetch_model(@concept_document_class, uuid)
  doc&.to_managed_concept
end

#concept_countObject



123
124
125
# File 'lib/glossarist/glossary_store.rb', line 123

def concept_count
  @package.model_count(@concept_document_class)
end

#concept_exists?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/glossarist/glossary_store.rb', line 127

def concept_exists?(uuid)
  @package.model_exists?(@concept_document_class, uuid)
end

#conceptsObject

── Concepts ──



89
90
91
92
93
# File 'lib/glossarist/glossary_store.rb', line 89

def concepts
  return @v1_concepts if @v1_concepts

  @package.models_for(@concept_document_class).map(&:to_managed_concept)
end

#each_concept(&block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/glossarist/glossary_store.rb', line 95

def each_concept(&block)
  return enum_for(:each_concept) unless block

  if @v1_concepts
    @v1_concepts.each(&block)
  else
    @package.models_for(@concept_document_class).each do |doc|
      yield doc.to_managed_concept
    end
  end
end

#figuresObject

── Dataset-level non-verbal entities ──

Loaded lazily from the dataset's figures/, tables/, formulas/ subdirectories. Each YAML file is parsed as the corresponding model (Figure, Table, Formula). The entities are referenced from ManagedConceptData via FigureReference/TableReference/FormulaReference but live as standalone shared entities at the dataset level. Wired into ConceptToGlossTransform via the figures:/tables:/formulas: kwargs on transform_document.



193
194
195
# File 'lib/glossarist/glossary_store.rb', line 193

def figures
  @figures ||= load_dataset_entities("figures", Figure)
end

#formulasObject



201
202
203
# File 'lib/glossarist/glossary_store.rb', line 201

def formulas
  @formulas ||= load_dataset_entities("formulas", Formula)
end

#image(path) ⇒ Object

── Images ──



170
171
172
# File 'lib/glossarist/glossary_store.rb', line 170

def image(path)
  @package.asset(path)
end

#image_pathsObject



179
180
181
# File 'lib/glossarist/glossary_store.rb', line 179

def image_paths
  @package.asset_paths.select { |p| p.start_with?("images/") }
end

#load(path, format: nil) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/glossarist/glossary_store.rb', line 67

def load(path, format: nil)
  ext = File.extname(path).downcase
  if [".gcr", ".zip"].include?(ext)
    load_zip(path, format: format)
  else
    load_directory(path, format: format)
  end
end

#load_directory(path, format: nil) ⇒ Object

── Load ──



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/glossarist/glossary_store.rb', line 20

def load_directory(path, format: nil)
  @dataset_path = File.expand_path(path)
  if v1_dataset?(path)
    load_v1_fallback(path)
    return self
  end

  if legacy_managed_layout?(path)
    load_legacy_managed(path)
    return self
  end

  if grouped_at_root?(path)
    load_grouped_at_root(path)
    return self
  end

   = (path)
  @concept_document_class = resolve_concept_document_class()

  definition = GcrPackageDefinition.definition(
    concept_document_class: @concept_document_class,
  )
  @package = Lutaml::Store::PackageStore.load(
    definition, path, transport: :directory, format: format
  )

  ()
  self
end

#load_zip(path, format: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/glossarist/glossary_store.rb', line 51

def load_zip(path, format: nil)
  @dataset_path = File.expand_path(path)
   = (path)
  @concept_document_class = resolve_concept_document_class()

  definition = GcrPackageDefinition.definition(
    concept_document_class: @concept_document_class,
  )
  @package = Lutaml::Store::PackageStore.load(
    definition, path, transport: :zip, format: format
  )

  ()
  self
end

#metadataObject

── Metadata ──



133
134
135
# File 'lib/glossarist/glossary_store.rb', line 133

def 
  @package&.
end

#metadata=(value) ⇒ Object



137
138
139
140
# File 'lib/glossarist/glossary_store.rb', line 137

def metadata=(value)
  ensure_package
  @package. = value
end

#register_dataObject

── Register Data ──



144
145
146
# File 'lib/glossarist/glossary_store.rb', line 144

def register_data
  @package.models_for(RegisterData).first
end

#register_data=(value) ⇒ Object



148
149
150
151
152
153
# File 'lib/glossarist/glossary_store.rb', line 148

def register_data=(value)
  ensure_package
  existing = register_data
  @package.remove_model(RegisterData, existing.key) if existing
  @package.add_model(value)
end

#remove_concept(uuid) ⇒ Object



119
120
121
# File 'lib/glossarist/glossary_store.rb', line 119

def remove_concept(uuid)
  @package.remove_model(@concept_document_class, uuid)
end

#save_directory(path, format: nil, formats: {}) ⇒ Object

── Save ──



78
79
80
81
# File 'lib/glossarist/glossary_store.rb', line 78

def save_directory(path, format: nil, formats: {})
  @package.save(path, transport: :directory, format: format,
                      formats: formats)
end

#save_zip(path, format: nil, formats: {}) ⇒ Object



83
84
85
# File 'lib/glossarist/glossary_store.rb', line 83

def save_zip(path, format: nil, formats: {})
  @package.save(path, transport: :zip, format: format, formats: formats)
end

#statsObject

── Stats ──



207
208
209
# File 'lib/glossarist/glossary_store.rb', line 207

def stats
  @package&.stats
end

#tablesObject



197
198
199
# File 'lib/glossarist/glossary_store.rb', line 197

def tables
  @tables ||= load_dataset_entities("tables", Table)
end