Class: Glossarist::Validation::Rules::DatasetContext
- Inherits:
-
Object
- Object
- Glossarist::Validation::Rules::DatasetContext
- Defined in:
- lib/glossarist/validation/rules/dataset_context.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #actual_languages ⇒ Object
- #add_concept(concept) ⇒ Object
- #asset_index ⇒ Object
- #bibliography_index ⇒ Object
- #concept_ids ⇒ Object
- #concepts ⇒ Object
-
#dataset_register ⇒ Object
Loads the dataset’s register.yaml as a DatasetRegister (with hierarchical sections, urn, ordering).
- #declared_languages ⇒ Object
- #gcr? ⇒ Boolean
-
#initialize(path) ⇒ DatasetContext
constructor
A new instance of DatasetContext.
- #localization_index ⇒ Object
- #metadata ⇒ Object
- #read_zip_file(_name) ⇒ Object
- #referenced_l10n_uuids ⇒ Object
Constructor Details
#initialize(path) ⇒ DatasetContext
Returns a new instance of DatasetContext.
9 10 11 12 13 14 15 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 9 def initialize(path) @path = File.(path) @accumulated_concepts = [] @bibliography_index = nil @asset_index = nil @declared_languages = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 7 def path @path end |
Instance Method Details
#actual_languages ⇒ Object
62 63 64 65 66 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 62 def actual_languages @actual_languages ||= concepts.flat_map do |c| c.localizations.map(&:language_code) end.compact.uniq.sort end |
#add_concept(concept) ⇒ Object
17 18 19 20 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 17 def add_concept(concept) @accumulated_concepts << concept @concept_ids = nil end |
#asset_index ⇒ Object
47 48 49 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 47 def asset_index @asset_index ||= AssetIndex.build_from_concepts(concepts, @path) end |
#bibliography_index ⇒ Object
41 42 43 44 45 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 41 def bibliography_index @bibliography_index ||= BibliographyIndex.build_from_concepts( concepts, dataset_path: @path ) end |
#concept_ids ⇒ Object
26 27 28 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 26 def concept_ids @concept_ids ||= concepts.filter_map { |c| c.data&.id&.to_s }.to_set end |
#concepts ⇒ Object
22 23 24 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 22 def concepts @accumulated_concepts end |
#dataset_register ⇒ Object
Loads the dataset’s register.yaml as a DatasetRegister (with hierarchical sections, urn, ordering). Returns nil if no register.yaml exists or it uses the legacy format.
37 38 39 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 37 def dataset_register @dataset_register ||= load_dataset_register end |
#declared_languages ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 51 def declared_languages @declared_languages ||= begin reg = load_register_data if reg && reg["languages"].is_a?(Array) reg["languages"] else actual_languages end end end |
#gcr? ⇒ Boolean
78 79 80 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 78 def gcr? false end |
#localization_index ⇒ Object
68 69 70 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 68 def localization_index @localization_index ||= build_localization_index end |
#metadata ⇒ Object
30 31 32 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 30 def nil end |
#read_zip_file(_name) ⇒ Object
82 83 84 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 82 def read_zip_file(_name) nil end |
#referenced_l10n_uuids ⇒ Object
72 73 74 75 76 |
# File 'lib/glossarist/validation/rules/dataset_context.rb', line 72 def referenced_l10n_uuids @referenced_l10n_uuids ||= concepts.flat_map do |c| (c.data.localized_concepts || {}).values end.to_set end |