glossarist 2.3.8 → 2.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 455c768825abe3d31abeb221718eb6d9385478fe1a32645ebaae67b82b7bda14
4
- data.tar.gz: 9fe994e3a6f2cc3b306c533e620f5faf432f1f4b48a888f059a4ecbeba5fc323
3
+ metadata.gz: 92a374af660211342e4f275381d50abb770cd2db1dc13a605d41d1e688ef75d2
4
+ data.tar.gz: 6971b2ac8948034157b07adfbe81d805fffe12b90989f4cad628368a57cc1abb
5
5
  SHA512:
6
- metadata.gz: 26e205c1940c3aa3eabeef7553b0e334d63d6365e10f4e97e0fd59acc3c37cfc7f7c19d707dac98c61d021b3b689d86074af3bad2f37a19aa95328703557fe19
7
- data.tar.gz: ba10c0a69e804726607bed7ca36563ecf20b849a5c100a57bbd9409313b2eea0946ebbbdea048aede5c6596bd7babd72c49c125e58d096ce7c44561afa8eee4c
6
+ metadata.gz: e748889d5afa2a7be0091e4a4d65937e7f2dbbfcf40fbcaa0bb186a16c7283b0d7150a573c7a02d969a5ad2623eef13b5f57a2acf912db6810717d7666b0fd94
7
+ data.tar.gz: b866f37821ea3ed8964ae2fe7942082e4f8a98c41766ca0f948ab0a3b1956ecb61c232a8cbb377d7759d0e08c02c9336c6d722fdd2c4d3cb951e4e6c183def98
data/README.adoc CHANGED
@@ -33,7 +33,18 @@ gem install glossarist
33
33
 
34
34
  === Reading a Glossarist model V2 from files
35
35
 
36
- To load the glossarist model V2 dataset
36
+ Glossarist model V2 dataset is a collection of concepts and their localized
37
+ concepts in the form of YAML files.
38
+
39
+ The storage structure of the dataset has 2 forms:
40
+
41
+ 1. Each concept is stored in a concept YAML file and its localized concepts are
42
+ stored in separate YAML files. The concept files are stored in the `concepts`
43
+ folder and its localized concepts are stored in the `localized_concepts` folder.
44
+ 2. Each concept and its related localized concepts are stored in a single YAML
45
+ file. The concept files are stored in the `concepts` folder.
46
+
47
+ To load the glossarist model V2 dataset:
37
48
 
38
49
  [,ruby]
39
50
  ----
@@ -43,10 +54,11 @@ collection.load_from_files("path/to/glossarist-v2-dataset")
43
54
 
44
55
  === Writing a Glossarist model V2 to files
45
56
 
46
- To wite the glossarist model V2 dataset to files
57
+ To write the glossarist model V2 dataset to files:
47
58
 
48
59
  [,ruby]
49
60
  ----
61
+ # load the collection from files
50
62
  collection = Glossarist::ManagedConceptCollection.new
51
63
  collection.load_from_files("path/to/glossarist-v2-dataset")
52
64
 
@@ -55,6 +67,20 @@ collection.load_from_files("path/to/glossarist-v2-dataset")
55
67
  collection.save_to_files("path/to/glossarist-v2-dataset")
56
68
  ----
57
69
 
70
+ To write the glossarist model V2 dataset with concepts and their
71
+ localized concepts grouped into single files:
72
+
73
+ [,ruby]
74
+ ----
75
+ # load the collection from files
76
+ collection = Glossarist::ManagedConceptCollection.new
77
+ collection.load_from_files("path/to/glossarist-v2-dataset")
78
+
79
+ # ... Update the collection ...
80
+
81
+ collection.save_grouped_concepts_to_files("path/to/glossarist-v2-dataset")
82
+ ----
83
+
58
84
  === ManagedConceptCollection
59
85
 
60
86
  This is a collection for <<managed-concept,managed concepts>>. It includes the ruby 'Enumerable' module.
@@ -112,7 +112,7 @@ module Glossarist
112
112
  end
113
113
  end
114
114
 
115
- def clause_from_yaml(model, value)
115
+ def clause_from_yaml(model, value) # rubocop:disable Metrics/AbcSize
116
116
  # accepts old format like
117
117
  # clause: "11"
118
118
  # or new format like
@@ -123,12 +123,11 @@ module Glossarist
123
123
  locality.type = value["type"] || "clause"
124
124
  locality.reference_from = value["reference_from"] || value
125
125
  locality.reference_to = value["reference_to"] if value["reference_to"]
126
- locality.validate!
127
126
  else
128
127
  locality.type = "clause"
129
128
  locality.reference_from = value
130
- locality.validate!
131
129
  end
130
+ locality.validate!
132
131
 
133
132
  model.locality = locality
134
133
  end
@@ -77,7 +77,7 @@ module Glossarist
77
77
  end
78
78
 
79
79
  def concepts_glob
80
- File.join(path, "concept-*.{yaml,yml}")
80
+ File.file?(path) ? path : File.join(path, "concept-*.{yaml,yml}")
81
81
  end
82
82
  end
83
83
  end
@@ -85,8 +85,7 @@ module Glossarist
85
85
 
86
86
  def date_accepted_to_yaml(model, doc)
87
87
  if model.date_accepted
88
- doc["date_accepted"] =
89
- model.date_accepted.date.iso8601
88
+ doc["date_accepted"] = model.date_accepted.date.iso8601
90
89
  end
91
90
  end
92
91
 
@@ -94,8 +93,13 @@ module Glossarist
94
93
  return if model.date_accepted
95
94
 
96
95
  model.data.dates ||= []
97
- model.data.dates << ConceptDate.of_yaml({ "date" => value,
98
- "type" => "accepted" })
96
+ model.data.dates << ConceptDate.of_yaml(
97
+ { "date" => value, "type" => "accepted" },
98
+ )
99
+
100
+ model.date_accepted = model.data.dates.find do |d|
101
+ d.type == "accepted"
102
+ end
99
103
  end
100
104
 
101
105
  def uuid
@@ -12,9 +12,11 @@ module Glossarist
12
12
  collection ||= ManagedConceptCollection.new
13
13
 
14
14
  Dir.glob(concepts_glob) do |filename|
15
- concept = load_concept_from_file(filename)
15
+ concepts = load_concept_from_file(filename)
16
16
 
17
- collection.store(concept)
17
+ concepts.each do |concept|
18
+ collection.store(concept)
19
+ end
18
20
  end
19
21
  end
20
22
 
@@ -24,30 +26,67 @@ module Glossarist
24
26
  end
25
27
  end
26
28
 
29
+ def save_grouped_concepts_to_files(managed_concepts)
30
+ managed_concepts.each do |concept|
31
+ save_grouped_concepts_to_file(concept)
32
+ end
33
+ end
34
+
35
+ def group_concept_hashes(mixed_hashes)
36
+ concept_hashes = mixed_hashes.select do |concept_hash|
37
+ !concept_hash["data"]["localized_concepts"].nil? ||
38
+ !concept_hash["data"]["localizedConcepts"].nil?
39
+ end
40
+
41
+ localized_concept_hashes = mixed_hashes.select do |concept_hash|
42
+ concept_hash["data"]["localized_concepts"].nil? &&
43
+ concept_hash["data"]["localizedConcepts"].nil?
44
+ end
45
+
46
+ [concept_hashes, localized_concept_hashes]
47
+ end
48
+
27
49
  def load_concept_from_file(filename)
28
- concept_hash = Psych.safe_load(File.read(filename),
29
- permitted_classes: [Date, Time])
30
- concept_hash["uuid"] = concept_hash["id"] || File.basename(filename, ".*")
50
+ mixed_hashes = YAML.load_stream(File.read(filename))
51
+ concepts = []
52
+
53
+ concept_hashes, localized_concept_hashes =
54
+ group_concept_hashes(mixed_hashes)
31
55
 
32
- concept = Config.class_for(:managed_concept).of_yaml(concept_hash)
56
+ concept_hashes.each do |concept_hash|
57
+ concept_hash["uuid"] = concept_hash["id"] ||
58
+ File.basename(filename, ".*")
59
+ concept = Config.class_for(:managed_concept).of_yaml(concept_hash)
33
60
 
34
- concept.data.localized_concepts.each_value do |id|
35
- localized_concept = load_localized_concept(id)
36
- concept.add_l10n(localized_concept)
61
+ concept.data.localized_concepts.each_value do |id|
62
+ localized_concept =
63
+ load_localized_concept(id, localized_concept_hashes)
64
+ concept.add_l10n(localized_concept)
65
+ end
66
+
67
+ concepts << concept
37
68
  end
38
69
 
39
- concept
70
+ concepts
40
71
  rescue Psych::SyntaxError => e
41
72
  raise Glossarist::ParseError.new(filename: filename, line: e.line)
42
73
  end
43
74
 
44
- def load_localized_concept(id)
45
- concept_hash = Psych.safe_load(
46
- File.read(localized_concept_path(id)),
47
- permitted_classes: [Date, Time],
48
- )
49
- concept_hash["uuid"] = id
75
+ def load_localized_concept(id, localized_concept_hashes = [])
76
+ {}
77
+
78
+ concept_hash = if localized_concept_hashes.empty?
79
+ Psych.safe_load(
80
+ File.read(localized_concept_path(id)),
81
+ permitted_classes: [Date, Time],
82
+ )
83
+ else
84
+ localized_concept_hashes.find do |hash|
85
+ hash["id"] == id
86
+ end
87
+ end
50
88
 
89
+ concept_hash["uuid"] = id
51
90
  Config.class_for(:localized_concept).of_yaml(concept_hash)
52
91
  rescue Psych::SyntaxError => e
53
92
  raise Glossarist::ParseError.new(filename: filename, line: e.line)
@@ -71,7 +110,27 @@ module Glossarist
71
110
  end
72
111
  end
73
112
 
113
+ def save_grouped_concepts_to_file(concept)
114
+ @localized_concepts_path ||= "localized_concept"
115
+ concept_dir = File.join(path, "concept")
116
+
117
+ Dir.mkdir(concept_dir) unless Dir.exist?(concept_dir)
118
+
119
+ content = []
120
+
121
+ filename = File.join(concept_dir, "#{concept.uuid}.yaml")
122
+ content << concept.to_yaml
123
+
124
+ concept.localized_concepts.each_key do |lang|
125
+ content << concept.localization(lang).to_yaml
126
+ end
127
+
128
+ File.write(filename, content.join("\n"))
129
+ end
130
+
74
131
  def concepts_glob
132
+ return path if File.file?(path)
133
+
75
134
  if v1_collection?
76
135
  File.join(path, "concept-*.{yaml,yml}")
77
136
  else
@@ -102,8 +161,6 @@ module Glossarist
102
161
  return actual_path
103
162
  end
104
163
  end
105
-
106
- actual_path
107
164
  end
108
165
 
109
166
  def v1_collection?
@@ -52,13 +52,15 @@ module Glossarist
52
52
  alias :l10n :localization
53
53
 
54
54
  def date_accepted_from_yaml(model, value)
55
- model.dates ||= []
56
- model.dates << ConceptDate.of_yaml({ "date" => value,
57
- "type" => "accepted" })
55
+ model.date_accepted = ConceptDate.of_yaml(
56
+ { "date" => value, "type" => "accepted" },
57
+ )
58
58
  end
59
59
 
60
60
  def date_accepted_to_yaml(model, doc)
61
- doc["date_accepted"] = model.date_accepted.date if model.date_accepted
61
+ if model.date_accepted
62
+ doc["date_accepted"] = model.date_accepted.date.iso8601
63
+ end
62
64
  end
63
65
 
64
66
  def uuid_to_yaml(model, doc)
@@ -70,5 +70,10 @@ module Glossarist
70
70
  @concept_manager.path = path
71
71
  @concept_manager.save_to_files(@managed_concepts)
72
72
  end
73
+
74
+ def save_grouped_concepts_to_files(path)
75
+ @concept_manager.path = path
76
+ @concept_manager.save_grouped_concepts_to_files(@managed_concepts)
77
+ end
73
78
  end
74
79
  end
@@ -4,5 +4,5 @@
4
4
  #
5
5
 
6
6
  module Glossarist
7
- VERSION = "2.3.8"
7
+ VERSION = "2.3.10"
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glossarist
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.8
4
+ version: 2.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-09 00:00:00.000000000 Z
11
+ date: 2025-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model