glossarist 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +65 -0
  4. data/README.adoc +2 -2
  5. data/config.yml +1 -1
  6. data/glossarist.gemspec +1 -0
  7. data/lib/glossarist/asset.rb +4 -9
  8. data/lib/glossarist/citation.rb +73 -41
  9. data/lib/glossarist/collection.rb +2 -11
  10. data/lib/glossarist/collections/asset_collection.rb +0 -3
  11. data/lib/glossarist/collections/bibliography_collection.rb +1 -1
  12. data/lib/glossarist/concept.rb +67 -206
  13. data/lib/glossarist/concept_data.rb +66 -0
  14. data/lib/glossarist/concept_date.rb +7 -11
  15. data/lib/glossarist/concept_manager.rb +19 -29
  16. data/lib/glossarist/concept_set.rb +6 -4
  17. data/lib/glossarist/concept_source.rb +15 -58
  18. data/lib/glossarist/config.rb +4 -4
  19. data/lib/glossarist/designation/abbreviation.rb +15 -16
  20. data/lib/glossarist/designation/base.rb +16 -15
  21. data/lib/glossarist/designation/expression.rb +18 -26
  22. data/lib/glossarist/designation/grammar_info.rb +29 -45
  23. data/lib/glossarist/designation/graphical_symbol.rb +12 -8
  24. data/lib/glossarist/designation/letter_symbol.rb +13 -11
  25. data/lib/glossarist/designation/symbol.rb +11 -13
  26. data/lib/glossarist/designation.rb +3 -3
  27. data/lib/glossarist/detailed_definition.rb +6 -24
  28. data/lib/glossarist/error.rb +4 -4
  29. data/lib/glossarist/glossary_definition.rb +6 -3
  30. data/lib/glossarist/localized_concept.rb +17 -62
  31. data/lib/glossarist/managed_concept.rb +74 -146
  32. data/lib/glossarist/managed_concept_collection.rb +15 -24
  33. data/lib/glossarist/managed_concept_data.rb +47 -0
  34. data/lib/glossarist/non_verb_rep.rb +10 -13
  35. data/lib/glossarist/related_concept.rb +14 -21
  36. data/lib/glossarist/utilities/uuid.rb +10 -5
  37. data/lib/glossarist/utilities.rb +0 -2
  38. data/lib/glossarist/version.rb +1 -1
  39. data/lib/glossarist.rb +10 -9
  40. metadata +23 -13
  41. data/lib/glossarist/model.rb +0 -40
  42. data/lib/glossarist/utilities/boolean_attributes.rb +0 -35
  43. data/lib/glossarist/utilities/enum/class_methods.rb +0 -99
  44. data/lib/glossarist/utilities/enum/enum_collection.rb +0 -45
  45. data/lib/glossarist/utilities/enum/instance_methods.rb +0 -55
  46. data/lib/glossarist/utilities/enum.rb +0 -21
  47. data/lib/glossarist/v1_reader.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe8b9555663cedc2258a960b19a10f9d6fc4575faf70006e1223c69f95678451
4
- data.tar.gz: fbdd27366d93b637882ad7dd3b77bfbaca9ae68c489403d7595fbe39af901e68
3
+ metadata.gz: 04b9e5d5f00de57e8d2c9aff73d25697758be004f33c5d02c0fdbf6254c69521
4
+ data.tar.gz: bca6a55ce2c23c374ab5d0e8745803f5ea77af3535ab94835726eeb06f331600
5
5
  SHA512:
6
- metadata.gz: 2e7030a8e328ee775641e8c4637b458c6746b872d597235bad00977c78a97d56f21ed48bbb9ef11ab0209ba74a93f7aeac19121bca32bd8c71aecdf67601223b
7
- data.tar.gz: 1a5ddbc5c71542eb7f258d17c601cd08b54041053ddfb1089a5f6e7eca28dfb360fe2b1c21da4bfa9d8474c333ce37376aeccbf75fc609dd2cea3e2e28c1acd2
6
+ metadata.gz: 1fa6e324a0f5a72a682a30492fa440731570da4f1b976b293318bd331b888743702e8241b9135a8a4aacc56cbdf266ca1319de9519fa8c0c09f56d9e9fa0e308
7
+ data.tar.gz: '09cc267101990c505ffeb3798887fc79d42b8c0aef6aa25424971095d5c745fa1a9bd9142f99adf7c012c7dce0d670e07ddfb932d85ca65603d6c5c9b9cbbd0f'
data/.rubocop.yml CHANGED
@@ -2,6 +2,7 @@
2
2
  # See https://github.com/metanorma/cimas
3
3
  inherit_from:
4
4
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
5
+ - .rubocop_todo.yml
5
6
 
6
7
  # local repo-specific modifications
7
8
  # ...
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,65 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2025-01-16 08:32:21 UTC using RuboCop version 1.70.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'glossarist.gemspec'
15
+
16
+ # Offense count: 64
17
+ # This cop supports safe autocorrection (--autocorrect).
18
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
19
+ # URISchemes: http, https
20
+ Layout/LineLength:
21
+ Enabled: false
22
+
23
+ # Offense count: 1
24
+ # Configuration parameters: AllowedMethods.
25
+ # AllowedMethods: enums
26
+ Lint/ConstantDefinitionInBlock:
27
+ Exclude:
28
+ - 'spec/unit/utilities/common_functions_spec.rb'
29
+
30
+ # Offense count: 2
31
+ Lint/DuplicateMethods:
32
+ Exclude:
33
+ - 'lib/glossarist/managed_concept.rb'
34
+
35
+ # Offense count: 3
36
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
37
+ Metrics/AbcSize:
38
+ Exclude:
39
+ - 'lib/glossarist/concept_manager.rb'
40
+ - 'lib/glossarist/utilities/uuid.rb'
41
+
42
+ # Offense count: 2
43
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
44
+ Metrics/CyclomaticComplexity:
45
+ Exclude:
46
+ - 'lib/glossarist/designation/expression.rb'
47
+ - 'lib/glossarist/managed_concept.rb'
48
+
49
+ # Offense count: 6
50
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
51
+ Metrics/MethodLength:
52
+ Max: 20
53
+
54
+ # Offense count: 1
55
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
56
+ Metrics/PerceivedComplexity:
57
+ Exclude:
58
+ - 'lib/glossarist/designation/expression.rb'
59
+
60
+ # Offense count: 6
61
+ # This cop supports safe autocorrection (--autocorrect).
62
+ # Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
63
+ # SupportedStyles: annotated, template, unannotated
64
+ Style/FormatStringToken:
65
+ EnforcedStyle: unannotated
data/README.adoc CHANGED
@@ -210,7 +210,7 @@ There are two ways to initialize and populate a concept date
210
210
  [,ruby]
211
211
  ----
212
212
  concept_date = Glossarist::ConceptDate.new({
213
- date: "2010-11-01T00:00:00.000Z",
213
+ date: "2010-11-01T00:00:00+00:00",
214
214
  type: :accepted,
215
215
  })
216
216
  ----
@@ -221,7 +221,7 @@ concept_date = Glossarist::ConceptDate.new({
221
221
  ----
222
222
  concept_date = Glossarist::ConceptDate.new
223
223
  concept_date.type = :accepted
224
- concept_date.date = "2010-11-01T00:00:00.000Z"
224
+ concept_date.date = "2010-11-01T00:00:00+00:00"
225
225
  ----
226
226
 
227
227
  [[id,detailed-definition]]
data/config.yml CHANGED
@@ -52,12 +52,12 @@ abbreviation:
52
52
 
53
53
  grammar_info:
54
54
  boolean_attribute:
55
- - preposition
56
55
  - participle
57
56
  - adj
58
57
  - verb
59
58
  - adverb
60
59
  - noun
60
+ - preposition
61
61
  gender:
62
62
  - m
63
63
  - f
data/glossarist.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
+ spec.add_dependency "lutaml-model", "~> 0.5.0"
33
34
  spec.add_dependency "relaton", "~> 1.19"
34
35
  spec.add_dependency "thor"
35
36
  end
@@ -1,14 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
1
  module Glossarist
7
- class Asset
8
- attr_accessor :path
2
+ class Asset < Lutaml::Model::Serializable
3
+ attribute :path, :string
9
4
 
10
- def initialize(path)
11
- @path = path
5
+ yaml do
6
+ map :path, to: :path
12
7
  end
13
8
 
14
9
  def eql?(asset)
@@ -1,69 +1,101 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
1
  module Glossarist
7
- class Citation < Model
2
+ class Citation < Lutaml::Model::Serializable
8
3
  # Unstructured (plain text) reference.
9
4
  # @return [String]
10
- attr_accessor :text
5
+ attribute :text, :string
11
6
 
12
7
  # Source in structured reference.
13
8
  # @return [String]
14
- attr_accessor :source
9
+ attribute :source, :string
15
10
 
16
11
  # Document ID in structured reference.
17
12
  # @return [String]
18
- attr_accessor :id
13
+ attribute :id, :string
19
14
 
20
15
  # Document version in structured reference.
21
16
  # @return [String]
22
- attr_accessor :version
17
+ attribute :version, :string
23
18
 
24
19
  # @return [String]
25
20
  # Referred clause of the document.
26
- attr_accessor :clause
21
+ attribute :clause, :string
27
22
 
28
23
  # Link to document.
29
24
  # @return [String]
30
- attr_accessor :link
25
+ attribute :link, :string
31
26
 
32
27
  # Original ref text before parsing.
33
28
  # @return [String]
34
29
  # @note This attribute is likely to be removed or reworked in future.
35
30
  # It is arguably not relevant to Glossarist itself.
36
- attr_accessor :original
31
+ attribute :original, :string
32
+
33
+ attribute :ref, :string
34
+
35
+ yaml do
36
+ map :id, to: :id, with: { from: :id_from_yaml, to: :id_to_yaml }
37
+ map :text, to: :text, with: { from: :text_from_yaml, to: :text_to_yaml }
38
+ map :source, to: :source,
39
+ with: { from: :source_from_yaml, to: :source_to_yaml }
40
+ map :version, to: :version,
41
+ with: { from: :version_from_yaml, to: :version_to_yaml }
42
+ map :ref, to: :ref, with: { from: :ref_from_yaml, to: :ref_to_yaml }
43
+
44
+ map :clause, to: :clause
45
+ map :link, to: :link
46
+ map :original, to: :original
47
+ end
37
48
 
38
- # Whether it is a plain text ref.
39
- # @return [Boolean]
40
- def plain?
41
- (source && id && version).nil?
49
+ def ref_from_yaml(model, value)
50
+ model.ref = value
42
51
  end
43
52
 
44
- # Whether it is a structured ref.
45
- # @return [Boolean]
46
- def structured?
47
- !plain?
53
+ def ref_to_yaml(model, doc)
54
+ doc["ref"] = if model.structured?
55
+ ref_hash(model)
56
+ else
57
+ model.text
58
+ end
48
59
  end
49
60
 
50
- def to_h
51
- {
52
- "ref" => ref_to_h,
53
- "clause" => clause,
54
- "link" => link,
55
- "original" => original,
56
- }.compact
61
+ def id_from_yaml(model, value)
62
+ model.id = value
57
63
  end
58
64
 
59
- def self.from_h(hash)
60
- hash = hash.dup
65
+ def id_to_yaml(_model, _doc)
66
+ # skip, will be handled in ref
67
+ end
61
68
 
62
- ref_val = hash.delete("ref")
63
- hash.merge!(Hash === ref_val ? ref_val : {"text" => ref_val})
64
- hash.compact!
69
+ def text_from_yaml(model, value)
70
+ model.text = value
71
+ end
72
+
73
+ def text_to_yaml(_model, _doc)
74
+ # skip, will be handled in ref
75
+ end
76
+
77
+ def source_from_yaml(model, value)
78
+ model.source = value
79
+ end
65
80
 
66
- super(hash)
81
+ def source_to_yaml(_model, _doc)
82
+ # skip, will be handled in ref
83
+ end
84
+
85
+ def version_from_yaml(model, value)
86
+ model.version = value
87
+ end
88
+
89
+ def version_to_yaml(_model, _doc)
90
+ # skip, will be handled in ref
91
+ end
92
+
93
+ def ref_hash(model = self)
94
+ {
95
+ "source" => model.source,
96
+ "id" => model.id,
97
+ "version" => model.version,
98
+ }.compact
67
99
  end
68
100
 
69
101
  def ref=(ref)
@@ -76,14 +108,14 @@ module Glossarist
76
108
  end
77
109
  end
78
110
 
79
- private
111
+ def plain?
112
+ (source && id && version).nil?
113
+ end
80
114
 
81
- def ref_to_h
82
- if structured?
83
- { "source" => source, "id" => id, "version" => version }.compact
84
- else
85
- text
86
- end
115
+ # Whether it is a structured ref.
116
+ # @return [Boolean]
117
+ def structured?
118
+ !plain?
87
119
  end
88
120
  end
89
121
  end
@@ -1,8 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
1
  module Glossarist
7
2
  # @todo Add support for lazy concept loading.
8
3
  # @todo Consider extracting persistence backend to a separate class.
@@ -33,7 +28,6 @@ module Glossarist
33
28
  def fetch(id)
34
29
  @index[id]
35
30
  end
36
-
37
31
  alias :[] :fetch
38
32
 
39
33
  # If concept with given ID is present in this collection, returns that
@@ -44,7 +38,7 @@ module Glossarist
44
38
  # Concept ID
45
39
  # @return [Concept]
46
40
  def fetch_or_initialize(id)
47
- fetch(id) or store(Concept.new(id: id))
41
+ fetch(id) or store(Concept.of_yaml({ id: id }))
48
42
  end
49
43
 
50
44
  # Adds concept to the collection. If collection contains a concept with
@@ -55,7 +49,6 @@ module Glossarist
55
49
  def store(concept)
56
50
  @index[concept.id] = concept
57
51
  end
58
-
59
52
  alias :<< :store
60
53
 
61
54
  # Reads all concepts from files.
@@ -70,10 +63,8 @@ module Glossarist
70
63
  @index.each_value &method(:save_concept_to_file)
71
64
  end
72
65
 
73
- private
74
-
75
66
  def load_concept_from_file(filename)
76
- Concept.from_h(Psych.safe_load(File.read(filename)))
67
+ Concept.from_yaml(File.read(filename))
77
68
  rescue Psych::SyntaxError => e
78
69
  raise Glossarist::ParseError.new(filename: filename, line: e.line)
79
70
  end
@@ -3,9 +3,6 @@
3
3
  module Glossarist
4
4
  module Collections
5
5
  class AssetCollection < Set
6
- def initialize(assets)
7
- super
8
- end
9
6
  end
10
7
  end
11
8
  end
@@ -5,7 +5,7 @@ require "relaton"
5
5
  module Glossarist
6
6
  module Collections
7
7
  class BibliographyCollection < Relaton::Db
8
- def initialize(concepts, global_cache, local_cache)
8
+ def initialize(_concepts, global_cache, local_cache)
9
9
  super(global_cache, local_cache)
10
10
  end
11
11
 
@@ -1,244 +1,105 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
1
  module Glossarist
7
- class Concept < Model
8
- # Concept ID.
9
- # @return [String]
10
- attr_reader :id
11
-
12
- attr_writer :uuid
13
-
14
- # Concept designations.
15
- # @todo Alias +terms+ exists only for legacy reasons and will be removed.
16
- # @return [Array<Designations::Base>]
17
- attr_reader :designations
18
- alias :terms :designations
19
-
20
- # <<BasicDocument>>LocalizedString
21
- # @return [String]
22
- attr_accessor :domain
23
-
24
- # <<BasicDocument>>LocalizedString
25
- # @return [String]
26
- attr_accessor :subject
27
-
28
- # Concept definition.
29
- # @return [Array<DetailedDefinition>]
30
- attr_reader :definition
31
-
32
- # Non verbal representation of the concept.
33
- # @return [NonVerbRep]
34
- attr_accessor :non_verb_rep
35
-
36
- # Concept notes
37
- # @return [Array<DetailedDefinition>]
38
- attr_reader :notes
39
-
40
- # Concept examples
41
- # @return [Array<DetailedDefinition>]
42
- attr_reader :examples
43
-
44
- # Contains list of extended attributes
45
- attr_accessor :extension_attributes
46
-
47
- attr_accessor :lineage_source
48
- attr_accessor :lineage_source_similarity
49
-
50
- attr_accessor :release
51
-
52
- def initialize(*args)
53
- @localizations = {}
54
- @sources = Glossarist::Collections::Collection.new(klass: ConceptSource)
55
- @related = Glossarist::Collections::Collection.new(klass: RelatedConcept)
56
- @definition = Glossarist::Collections::Collection.new(klass: DetailedDefinition)
57
- @notes = Glossarist::Collections::Collection.new(klass: DetailedDefinition)
58
- @examples = Glossarist::Collections::Collection.new(klass: DetailedDefinition)
59
- @dates = Glossarist::Collections::Collection.new(klass: ConceptDate)
60
-
61
- @designations = Glossarist::Collections::DesignationCollection.new
62
- @extension_attributes = {}
63
-
64
- normalize_args(args)
65
-
66
- super
67
- end
68
-
69
- def uuid
70
- @uuid ||= Glossarist::Utilities::UUID.uuid_v5(
71
- Glossarist::Utilities::UUID::OID_NAMESPACE,
72
- to_h_no_uuid.to_yaml,
73
- )
2
+ class Concept < Lutaml::Model::Serializable
3
+ attribute :data, ConceptData, default: -> { ConceptData.new }
4
+ attribute :id, :string
5
+ attribute :uuid, :string
6
+ attribute :subject, :string
7
+ attribute :non_verb_rep, :string
8
+ attribute :extension_attributes, :string
9
+ attribute :lineage_source, :string
10
+ attribute :localizations, :hash
11
+ attribute :extension_attributes, :hash
12
+ attribute :termid, :string
13
+
14
+ yaml do
15
+ map :data, to: :data
16
+ map :termid, to: :termid
17
+ map :subject, to: :subject
18
+ map :non_verb_rep, to: :non_verb_rep
19
+ map :extension_attributes, to: :extension_attributes
20
+ map :lineage_source, to: :lineage_source
21
+ map :localizations, to: :localizations
22
+ map :extension_attributes, to: :extension_attributes
23
+
24
+ map :date_accepted,
25
+ with: { from: :date_accepted_from_yaml, to: :date_accepted_to_yaml }
26
+ map :uuid, to: :uuid, with: { to: :uuid_to_yaml, from: :uuid_from_yaml }
27
+ map :id, to: :id, with: { to: :id_to_yaml, from: :id_from_yaml }
28
+ map :identifier, to: :id, with: { to: :id_to_yaml, from: :id_from_yaml }
29
+ end
30
+
31
+ def designations
32
+ data.terms
74
33
  end
34
+ alias :terms :designations
75
35
 
76
- def id=(id)
77
- # Some of the glossaries that are not generated using glossarist, contains ids that are integers
78
- # so adding a temporary check until every glossary is updated using glossarist.
79
- if !id.nil? && (id.is_a?(String) || id.is_a?(Integer))
80
- @id = id
81
- else
82
- raise(Glossarist::Error, "Expect id to be a String or Integer, Got #{id.class} (#{id})")
83
- end
36
+ def definition
37
+ data.definition
84
38
  end
85
39
 
86
- alias :termid= :id=
87
- alias :identifier= :id=
88
-
89
- # List of authorative sources.
90
- # @todo Alias +authoritative_source+ exists for legacy reasons and may be
91
- # removed.
92
- # @return [Array<ConceptSource>]
93
- attr_reader :sources
94
-
95
- # return [Array<ConceptDate>]
96
- attr_reader :dates
97
-
98
- def examples=(examples)
99
- @examples.clear!
100
- examples&.each { |example| @examples << example }
40
+ def definition=(value)
41
+ data.definition = value
101
42
  end
102
43
 
103
- def notes=(notes)
104
- @notes.clear!
105
- notes&.each { |note| @notes << note }
44
+ def sources
45
+ data.sources
106
46
  end
107
47
 
108
- def definition=(definition)
109
- @definition.clear!
110
- definition&.each { |definition| @definition << definition }
48
+ def examples
49
+ data.examples
111
50
  end
112
51
 
113
- def designations=(designations)
114
- @designations.clear!
115
- designations&.each { |designation| @designations << designation }
52
+ def notes
53
+ data.notes
116
54
  end
117
55
 
118
- alias :terms= :designations=
119
-
120
56
  def preferred_designations
121
- @designations.select(&:preferred?)
57
+ data.terms.select(&:preferred?)
122
58
  end
123
-
124
59
  alias :preferred_terms :preferred_designations
125
60
 
126
- def dates=(dates)
127
- @dates.clear!
128
- dates&.each { |date| @dates << date }
129
- end
130
-
131
- def sources=(sources)
132
- @sources.clear!
133
- sources&.each { |source| @sources << source }
61
+ def date_accepted
62
+ data.date_accepted
134
63
  end
135
64
 
136
65
  def authoritative_source
137
- @sources.select { |source| source.authoritative? }
138
- end
139
-
140
- def authoritative_source=(sources)
141
- sources&.each do |source|
142
- @sources << source.merge({ "type" => "authoritative" })
143
- end
66
+ data.authoritative_source
144
67
  end
145
68
 
146
- def date_accepted=(date)
147
- date_hash = {
148
- "type" => "accepted",
149
- "date" => date,
150
- }
151
-
152
- @dates ||= []
153
- @dates << ConceptDate.new(date_hash)
69
+ def uuid_to_yaml(model, doc)
70
+ doc["id"] = model.uuid if model.uuid
154
71
  end
155
72
 
156
- def date_accepted
157
- return nil unless @dates
158
- @dates.find { |date| date.accepted? }
73
+ def uuid_from_yaml(model, value)
74
+ model.uuid = value
159
75
  end
160
76
 
161
- def to_h_no_uuid
162
- {
163
- "data" => {
164
- "dates" => dates&.map(&:to_h),
165
- "definition" => definition&.map(&:to_h),
166
- "examples" => examples&.map(&:to_h),
167
- "id" => id,
168
- "lineage_source_similarity" => lineage_source_similarity,
169
- "notes" => notes&.map(&:to_h),
170
- "release" => release,
171
- "sources" => sources.empty? ? nil : sources&.map(&:to_h),
172
- "terms" => (terms&.map(&:to_h) || []),
173
- "related" => related&.map(&:to_h),
174
- "domain" => domain,
175
- }.compact,
176
-
177
- "date_accepted" => date_accepted&.date,
178
-
179
- }.compact
180
- end
77
+ def id_to_yaml(model, doc); end
181
78
 
182
- def to_h
183
- to_h_no_uuid.merge("id" => uuid)
79
+ def id_from_yaml(model, value)
80
+ model.id = value
184
81
  end
185
82
 
186
- # @deprecated For legacy reasons only.
187
- # Implicit conversion (i.e. {#to_hash} alias) will be removed soon.
188
- alias :to_hash :to_h
189
-
190
- # rubocop:disable Metrics/AbcSize, Style/RescueModifier
191
- def self.from_h(hash)
192
- new.tap do |concept|
193
- concept.id = hash.dig("termid") || hash.dig("id")
194
- concept.sources = hash.dig("sources")
195
- concept.related = hash.dig("related")
196
- concept.definition = hash.dig("definition")
197
-
198
- hash.values
199
- .grep(Hash)
200
- .map { |subhash| Config.class_for(:localized_concept).from_h(subhash) rescue nil }
201
- .compact
202
-
203
- concept.related = hash.dig("related") || []
83
+ def date_accepted_to_yaml(model, doc)
84
+ if model.date_accepted
85
+ doc["date_accepted"] =
86
+ model.date_accepted.date.iso8601
204
87
  end
205
88
  end
206
- # rubocop:enable Metrics/AbcSize, Style/RescueModifier
207
89
 
208
- # All Related Concepts
209
- # @return [Array<RelatedConcept>]
210
- def related
211
- @related.empty? ? nil : @related
212
- end
90
+ def date_accepted_from_yaml(model, value)
91
+ return if model.date_accepted
213
92
 
214
- def related=(related)
215
- @related.clear!
216
- related&.each { |r| @related << r }
217
- end
218
-
219
- Glossarist::GlossaryDefinition::CONCEPT_DATE_TYPES.each do |type|
220
- # Sets the ConceptDate and add it to dates list of the specified type.
221
- define_method("date_#{type}=") do |date|
222
- date_hash = {
223
- "type" => type,
224
- "date" => date,
225
- }
226
- @dates ||= []
227
- @dates << ConceptDate.new(date_hash)
228
- end
93
+ model.data.dates ||= []
94
+ model.data.dates << ConceptDate.of_yaml({ "date" => value,
95
+ "type" => "accepted" })
229
96
  end
230
97
 
231
- def normalize_args(args)
232
- args.each do |arg|
233
- data = arg.delete("data")
234
-
235
- arg.merge!(data) if data
236
-
237
- if arg["sources"]
238
- arg.delete("authoritative_source")
239
- arg.delete("authoritativeSource")
240
- end
241
- end
98
+ def uuid
99
+ @uuid ||= Glossarist::Utilities::UUID.uuid_v5(
100
+ Glossarist::Utilities::UUID::OID_NAMESPACE,
101
+ data.to_yaml,
102
+ )
242
103
  end
243
104
  end
244
105
  end