glossarist 2.3.0 → 2.3.1

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.
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
@@ -3,9 +3,9 @@
3
3
  # (c) Copyright 2021 Ribose Inc.
4
4
  #
5
5
 
6
- require_relative "designation/abbreviation"
7
6
  require_relative "designation/base"
8
7
  require_relative "designation/expression"
8
+ require_relative "designation/abbreviation"
9
9
  require_relative "designation/grammar_info"
10
10
  require_relative "designation/symbol"
11
11
  require_relative "designation/graphical_symbol"
@@ -21,7 +21,7 @@ module Glossarist
21
21
  GraphicalSymbol => "graphical_symbol",
22
22
  LetterSymbol => "letter_symbol",
23
23
  }
24
- .tap { |h| h.merge!(h.invert) }
25
- .freeze
24
+ .tap { |h| h.merge!(h.invert) }
25
+ .freeze
26
26
  end
27
27
  end
@@ -1,31 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Glossarist
4
- class DetailedDefinition < Model
4
+ class DetailedDefinition < Lutaml::Model::Serializable
5
+ attribute :content, :string
6
+ attribute :sources, ConceptSource, collection: true
5
7
 
6
- def initialize(attributes = {})
7
- if attributes.is_a?(Hash)
8
- super
9
- else
10
- self.content = attributes
11
- end
12
- end
13
-
14
- # @return [String]
15
- attr_accessor :content
16
-
17
- # @return [Array<ConceptSource>]
18
- attr_reader :sources
19
-
20
- def sources=(sources)
21
- @sources = sources.map { |s| ConceptSource.new(s) }
22
- end
23
-
24
- def to_h
25
- {
26
- "content" => content,
27
- "sources" => sources&.map(&:to_h),
28
- }.compact
8
+ yaml do
9
+ map :content, to: :content
10
+ map :sources, to: :sources
29
11
  end
30
12
  end
31
13
  end
@@ -1,8 +1,8 @@
1
- require_relative "error/invalid_type_error"
2
- require_relative "error/invalid_language_code_error"
3
- require_relative "error/parse_error"
4
-
5
1
  module Glossarist
6
2
  class Error < StandardError
7
3
  end
8
4
  end
5
+
6
+ require_relative "error/invalid_type_error"
7
+ require_relative "error/invalid_language_code_error"
8
+ require_relative "error/parse_error"
@@ -4,7 +4,8 @@ require "yaml"
4
4
 
5
5
  module Glossarist
6
6
  module GlossaryDefinition
7
- config = YAML.load_file(File.expand_path("../../../config.yml", __FILE__)) || {}
7
+ config = YAML.load_file(File.expand_path("../../config.yml",
8
+ __dir__)) || {}
8
9
 
9
10
  CONCEPT_SOURCE_STATUSES = config.dig("concept_source", "status").freeze
10
11
 
@@ -14,13 +15,15 @@ module Glossarist
14
15
 
15
16
  ABBREVIATION_TYPES = config.dig("abbreviation", "type").freeze
16
17
 
17
- GRAMMAR_INFO_BOOLEAN_ATTRIBUTES = config.dig("grammar_info", "boolean_attribute").freeze
18
+ GRAMMAR_INFO_BOOLEAN_ATTRIBUTES = config.dig("grammar_info",
19
+ "boolean_attribute").freeze
18
20
 
19
21
  GRAMMAR_INFO_GENDERS = config.dig("grammar_info", "gender").freeze
20
22
 
21
23
  GRAMMAR_INFO_NUMBERS = config.dig("grammar_info", "number").freeze
22
24
 
23
- DESIGNATION_BASE_NORMATIVE_STATUSES = config.dig("designation", "base", "normative_status").freeze
25
+ DESIGNATION_BASE_NORMATIVE_STATUSES = config.dig("designation", "base",
26
+ "normative_status").freeze
24
27
 
25
28
  CONCEPT_DATE_TYPES = config.dig("concept_date", "type").freeze
26
29
 
@@ -1,75 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
1
  module Glossarist
7
2
  class LocalizedConcept < Concept
8
- # ISO 639-2 code for terminology.
9
- # @see https://www.loc.gov/standards/iso639-2/php/code_list.php code list
10
- # @return [String]
11
- attr_reader :language_code
12
-
13
- # Must be one of the following:
14
- # +notValid+, +valid+, +superseded+, +retired+.
15
- # @todo Proper type checking.
16
- # @note Works with strings, but soon they may be replaced with symbols.
17
- # @return [String]
18
- attr_accessor :entry_status
19
- alias_method :status=, :entry_status=
20
-
21
- # Must be one of the following:
22
- # +preferred+, +admitted+, +deprecated+.
23
- # @todo Proper type checking.
24
- # @note Works with strings, but soon they may be replaced with symbols.
25
- # @return [String]
26
- attr_accessor :classification
27
-
28
- # Temporary fields
29
- # @todo Need to remove these once the isotc211-glossary is fixed
30
- attr_accessor *%i[
31
- review_date
32
- review_decision_date
33
- review_decision_event
34
- review_type
35
- ]
3
+ attribute :classification, :string
4
+ attribute :review_type, :string
5
+ attribute :entry_status, :string
36
6
 
37
- def language_code=(language_code)
38
- if language_code.is_a?(String) && language_code.length == 3
39
- @language_code = language_code
40
- else
41
- raise Glossarist::InvalidLanguageCodeError.new(code: language_code)
42
- end
7
+ yaml do
8
+ map :classification, to: :classification
9
+ map :review_type, to: :review_type
43
10
  end
44
11
 
45
- def to_h_no_uuid # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
46
- hash = super
47
-
48
- hash["data"].merge!({
49
- "language_code" => language_code,
50
- "entry_status" => entry_status,
51
- "sources" => sources.empty? ? nil : sources&.map(&:to_h),
52
- "classification" => classification,
53
- "dates" => dates&.map(&:to_h),
54
- "review_date" => review_date,
55
- "review_decision_date" => review_decision_date,
56
- "review_decision_event" => review_decision_event,
57
- }.compact).merge!(@extension_attributes)
58
-
59
- hash["status"] = entry_status if entry_status
12
+ alias_method :status=, :entry_status=
60
13
 
61
- hash
14
+ def language_code
15
+ data.language_code
62
16
  end
63
17
 
64
- def self.from_h(hash)
65
- terms = hash["terms"]&.map { |h| Designation::Base.from_h(h) } || []
66
- sources = hash["authoritative_source"]&.each { |source| source.merge({ "type" => "authoritative" }) }
18
+ def entry_status
19
+ data.entry_status
20
+ end
67
21
 
68
- super(hash.merge({ "terms" => terms, "sources" => sources }))
22
+ def language_code=(value)
23
+ data.language_code = value
69
24
  end
70
25
 
71
- # @deprecated For legacy reasons only.
72
- # Implicit conversion (i.e. {#to_hash} alias) will be removed soon.
73
- alias :to_hash :to_h
26
+ def entry_status=(value)
27
+ data.entry_status = value
28
+ end
74
29
  end
75
30
  end
@@ -1,90 +1,102 @@
1
- # frozen_string_literal: true
1
+ require_relative "localized_concept"
2
2
 
3
3
  module Glossarist
4
- class ManagedConcept < Model
5
- include Glossarist::Utilities::Enum
4
+ class ManagedConcept < Lutaml::Model::Serializable
6
5
  include Glossarist::Utilities::CommonFunctions
7
6
 
8
- # @return [String]
9
- attr_accessor :id
10
- alias :termid= :id=
11
- alias :identifier= :id=
7
+ attribute :data, ManagedConceptData
12
8
 
13
- attr_accessor :uuid
9
+ attribute :related, RelatedConcept, collection: true
10
+ attribute :dates, ConceptDate, collection: true
11
+ attribute :sources, ConceptSource
12
+ attribute :date_accepted, ConceptDate
13
+ # TODO: convert to LocalizedConceptCollection when custom
14
+ # collections are implemented in lutaml-model
15
+ attribute :status, :string,
16
+ values: Glossarist::GlossaryDefinition::CONCEPT_STATUSES
14
17
 
15
- # @return [Array<RelatedConcept>]
16
- attr_reader :related
18
+ attribute :identifier, :string
19
+ alias :id :identifier
20
+ alias :id= :identifier=
17
21
 
18
- # @return [String]
19
- register_enum :status, Glossarist::GlossaryDefinition::CONCEPT_STATUSES
22
+ attribute :uuid, :string
20
23
 
21
- # return [Array<ConceptDate>]
22
- attr_reader :dates
24
+ yaml do
25
+ map :data, to: :data
26
+ map :id, with: { to: :identifier_to_yaml, from: :identifier_from_yaml }
27
+ map :identifier,
28
+ with: { to: :identifier_to_yaml, from: :identifier_from_yaml }
29
+ map :related, to: :related
30
+ map :dates, to: :dates
31
+ map :date_accepted,
32
+ with: { from: :date_accepted_from_yaml, to: :date_accepted_to_yaml }
33
+ map :status, to: :status
23
34
 
24
- # return [Array<LocalizedConcept>]
25
- attr_reader :localized_concepts
26
-
27
- # Concept group
28
- # @return [Array<String>]
29
- attr_reader :groups
30
-
31
- # List of authorative sources.
32
- # @return [Array<ConceptSource>]
33
- attr_reader :sources
35
+ map :uuid, to: :uuid, with: { from: :uuid_from_yaml, to: :uuid_to_yaml }
36
+ end
34
37
 
35
- # All localizations for this concept.
36
- #
37
- # Keys are language codes and values are instances of {LocalizedConcept}.
38
- # @return [Hash<String, LocalizedConcept>]
39
- attr_reader :localizations
38
+ def localized_concepts
39
+ data.localized_concepts
40
+ end
40
41
 
41
- def initialize(attributes = {})
42
- @localizations = {}
43
- @localized_concepts = {}
44
- @localized_concept_class = Config.class_for(:localized_concept)
45
- @uuid_namespace = Glossarist::Utilities::UUID::OID_NAMESPACE
42
+ def localized_concepts=(val)
43
+ data.localized_concepts = val
44
+ end
46
45
 
47
- attributes = symbolize_keys(attributes)
48
- @uuid = attributes[:uuid]
46
+ def localizations
47
+ data.localizations
48
+ end
49
49
 
50
- data = attributes.delete(:data) || {}
51
- data["groups"] = attributes[:groups]
52
- data["status"] = attributes[:status]
50
+ def localization(lang)
51
+ localizations[lang]
52
+ end
53
+ alias :l10n :localization
53
54
 
54
- data = symbolize_keys(data.compact)
55
+ def date_accepted_from_yaml(model, value)
56
+ model.dates ||= []
57
+ model.dates << ConceptDate.of_yaml({ "date" => value,
58
+ "type" => "accepted" })
59
+ end
55
60
 
56
- super(slice_keys(data, managed_concept_attributes))
61
+ def date_accepted_to_yaml(model, doc)
62
+ doc["date_accepted"] = model.date_accepted.date if model.date_accepted
57
63
  end
58
64
 
59
- def uuid
60
- @uuid ||= Glossarist::Utilities::UUID.uuid_v5(@uuid_namespace, to_h_no_uuid.to_yaml)
65
+ def uuid_to_yaml(model, doc)
66
+ doc["id"] = model.uuid if model.uuid
61
67
  end
62
68
 
63
- def related=(related)
64
- @related = related&.map { |r| RelatedConcept.new(r) }
69
+ def uuid_from_yaml(model, value)
70
+ model.uuid = value if value
65
71
  end
66
72
 
67
- def dates=(dates)
68
- @dates = dates&.map { |d| ConceptDate.new(d) }
73
+ def uuid
74
+ @uuid ||= Glossarist::Utilities::UUID.uuid_v5(
75
+ Glossarist::Utilities::UUID::OID_NAMESPACE,
76
+ to_yaml(except: [:uuid]),
77
+ )
69
78
  end
70
79
 
71
- def groups=(groups)
72
- return unless groups
80
+ def identifier_to_yaml(model, doc)
81
+ value = model.identifier || model.id
82
+ doc["id"] = value if value && !doc["id"]
83
+ end
73
84
 
74
- @groups = groups.is_a?(Array) ? groups : [groups]
85
+ def identifier_from_yaml(model, value)
86
+ model.identifier = value || model.identifier
75
87
  end
76
88
 
77
- def localized_concepts=(localized_concepts)
78
- return unless localized_concepts
89
+ def localized_concepts=(localized_concepts_collection)
90
+ return unless localized_concepts_collection
79
91
 
80
- if localized_concepts.is_a?(Hash)
81
- @localized_concepts = stringify_keys(localized_concepts)
92
+ if localized_concepts_collection.is_a?(Hash)
93
+ @localized_concepts = stringify_keys(localized_concepts_collection)
82
94
  else
83
- localized_concepts.each do |localized_concept_hash|
84
- lang = localized_concept_hash["language_code"].to_s
95
+ localized_concepts_collection.each do |localized_concept_hash|
96
+ lang = localized_concept_hash.dig("data", "language_code").to_s
85
97
 
86
98
  localized_concept = add_localization(
87
- @localized_concept_class.new(localized_concept_hash["data"] || localized_concept_hash),
99
+ Config.class_for(:localized_concept).of_yaml(localized_concept_hash),
88
100
  )
89
101
 
90
102
  @localized_concepts[lang] = localization(lang).uuid
@@ -93,72 +105,22 @@ module Glossarist
93
105
  end
94
106
  end
95
107
  end
96
-
97
- def sources=(sources)
98
- @sources = sources&.map do |source|
99
- ConceptSource.new(source)
100
- end || []
101
- end
102
-
103
- def localizations=(localizations)
104
- return unless localizations
105
-
106
- @localizations = {}
107
-
108
- localizations.each do |localized_concept|
109
- unless localized_concept.is_a?(@localized_concept_class)
110
- localized_concept = @localized_concept_class.new(
111
- localized_concept["data"] || localized_concept,
112
- )
113
- end
114
-
115
- add_l10n(localized_concept)
116
- end
117
- end
118
-
119
- def localizations_hash
120
- @localizations.map do |key, localized_concept|
121
- [key, localized_concept.to_h]
122
- end.to_h
123
- end
108
+ attr_reader :localized_concepts
124
109
 
125
110
  # Adds concept localization.
126
111
  # @param localized_concept [LocalizedConcept]
127
112
  def add_localization(localized_concept)
128
113
  lang = localized_concept.language_code
129
- @localized_concepts[lang] = @localized_concepts[lang] || localized_concept.uuid
114
+ @localized_concepts ||= {}
115
+ @localized_concepts[lang] =
116
+ @localized_concepts[lang] || localized_concept.uuid
130
117
  localizations.store(lang, localized_concept)
131
118
  end
132
-
133
119
  alias :add_l10n :add_localization
134
120
 
135
121
  # Returns concept localization.
136
122
  # @param lang [String] language code
137
123
  # @return [LocalizedConcept]
138
- def localization(lang)
139
- localizations[lang]
140
- end
141
-
142
- alias :l10n :localization
143
-
144
- def to_h_no_uuid
145
- {
146
- "data" => {
147
- "identifier" => id,
148
- "localized_concepts" => localized_concepts.empty? ? nil : localized_concepts,
149
- "groups" => groups,
150
- "sources" => sources&.map(&:to_h),
151
- }.compact,
152
- "related" => related&.map(&:to_h),
153
- "date_accepted" => date_accepted&.date,
154
- "status" => status,
155
- }.compact
156
- end
157
-
158
- def to_h
159
- to_h_no_uuid.merge("id" => uuid)
160
- end
161
-
162
124
  def default_designation
163
125
  localized = localization("eng") || localizations.values.first
164
126
  terms = localized&.preferred_terms&.first || localized&.terms&.first
@@ -167,47 +129,13 @@ module Glossarist
167
129
 
168
130
  def default_definition
169
131
  localized = localization("eng") || localizations.values.first
170
- localized&.definition&.first&.content
132
+ localized&.data&.definition&.first&.content
171
133
  end
172
134
 
173
135
  def default_lang
174
136
  localization("eng") || localizations.values.first
175
137
  end
176
138
 
177
- def date_accepted=(date)
178
- date_hash = {
179
- "type" => "accepted",
180
- "date" => date,
181
- }
182
-
183
- @dates ||= []
184
- @dates << ConceptDate.new(date_hash)
185
- end
186
-
187
- def date_accepted
188
- return nil unless @dates
189
- @dates.find { |date| date.accepted? }
190
- end
191
-
192
- def managed_concept_attributes
193
- %i[
194
- data
195
- id
196
- identifier
197
- uuid
198
- related
199
- status
200
- dates
201
- date_accepted
202
- dateAccepted
203
- localized_concepts
204
- localizedConcepts
205
- localizations
206
- groups
207
- sources
208
- ].compact
209
- end
210
-
211
139
  Glossarist::GlossaryDefinition::RELATED_CONCEPT_TYPES.each do |type|
212
140
  # List of related concepts of the specified type.
213
141
  # @return [Array<RelatedConcept>]
@@ -1,36 +1,23 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
2
  class ManagedConceptCollection
5
3
  include Enumerable
6
4
 
5
+ attr_accessor :managed_concepts
6
+
7
7
  def initialize
8
- @managed_concepts = {}
8
+ @managed_concepts = []
9
9
  @managed_concepts_ids = {}
10
10
  @concept_manager = ConceptManager.new
11
11
  end
12
12
 
13
- # @return [Array<ManagedConcept>]
14
- def managed_concepts
15
- @managed_concepts.values
16
- end
17
-
18
- def managed_concepts=(managed_concepts = [])
19
- managed_concepts.each do |managed_concept|
20
- store(Config.class_for(:managed_concept).new(managed_concept))
21
- end
22
-
23
- @managed_concepts.values
24
- end
25
-
26
13
  def to_h
27
14
  {
28
- "managed_concepts" => managed_concepts.map(&:to_h),
15
+ "managed_concepts" => managed_concepts.map(&:to_yaml_hash),
29
16
  }.compact
30
17
  end
31
18
 
32
19
  def each(&block)
33
- @managed_concepts.each_value(&block)
20
+ @managed_concepts.each(&block)
34
21
  end
35
22
 
36
23
  # Returns concept with given ID, if it is present in collection, or +nil+
@@ -40,9 +27,10 @@ module Glossarist
40
27
  # ManagedConcept ID
41
28
  # @return [ManagedConcept, nil]
42
29
  def fetch(id)
43
- @managed_concepts[id] || @managed_concepts[@managed_concepts_ids[id]]
30
+ @managed_concepts.find do |c|
31
+ c.uuid == id || c.uuid == @managed_concepts_ids[id]
32
+ end
44
33
  end
45
-
46
34
  alias :[] :fetch
47
35
 
48
36
  # If ManagedConcept with given ID is present in this collection, then
@@ -53,7 +41,7 @@ module Glossarist
53
41
  # ManagedConcept ID
54
42
  # @return [ManagedConcept]
55
43
  def fetch_or_initialize(id)
56
- fetch(id) or store(Config.class_for(:managed_concept).new(data: { id: id }))
44
+ fetch(id) or store(Config.class_for(:managed_concept).of_yaml(data: { id: id }))
57
45
  end
58
46
 
59
47
  # Adds concept to the collection. If collection contains a concept with
@@ -62,12 +50,15 @@ module Glossarist
62
50
  # @param managed_concept [ManagedConcept]
63
51
  # ManagedConcept about to be added
64
52
  def store(managed_concept)
65
- @managed_concepts[managed_concept.uuid] = managed_concept
66
- @managed_concepts_ids[managed_concept.id] = managed_concept.uuid if managed_concept.id
53
+ @managed_concepts ||= []
54
+ @managed_concepts << managed_concept
55
+ if managed_concept.data.id
56
+ @managed_concepts_ids[managed_concept.data.id] =
57
+ managed_concept.uuid
58
+ end
67
59
 
68
60
  managed_concept
69
61
  end
70
-
71
62
  alias :<< :store
72
63
 
73
64
  def load_from_files(path)
@@ -0,0 +1,47 @@
1
+ module Glossarist
2
+ class ManagedConceptData < Lutaml::Model::Serializable
3
+ include Glossarist::Utilities::CommonFunctions
4
+
5
+ attribute :id, :string
6
+ attribute :localized_concepts, :hash
7
+ attribute :groups, :string, collection: true
8
+ attribute :sources, ConceptSource, collection: true
9
+ attribute :localizations, :hash, collection: true, default: -> { {} }
10
+
11
+ yaml do
12
+ map %i[id identifier], to: :id,
13
+ with: { to: :id_to_yaml, from: :id_from_yaml }
14
+ map %i[localized_concepts localizedConcepts], to: :localized_concepts
15
+ map :groups, to: :groups
16
+ map :sources, to: :sources
17
+ map :localizations, to: :localizations,
18
+ with: { from: :localizations_from_yaml, to: :localizations_to_yaml }
19
+ end
20
+
21
+ def id_to_yaml(model, doc)
22
+ value = model.id || model.identifier
23
+ doc["identifier"] = value if value && !doc["identifier"]
24
+ end
25
+
26
+ def id_from_yaml(model, value)
27
+ model.id = value unless model.id
28
+ end
29
+
30
+ def localizations_from_yaml(model, value)
31
+ model.localizations ||= {}
32
+
33
+ value.each do |localized_concept_hash|
34
+ localized_concept = Glossarist::LocalizedConcept.of_yaml(localized_concept_hash)
35
+ model.localizations[localized_concept.language_code] = localized_concept
36
+ end
37
+ end
38
+
39
+ def localizations_to_yaml(model, doc); end
40
+
41
+ def authoritative_source
42
+ return [] unless sources
43
+
44
+ sources.select(&:authoritative?)
45
+ end
46
+ end
47
+ end
@@ -1,18 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
- class NonVerbRep
5
- attr_accessor :image
6
- attr_accessor :table
7
- attr_accessor :formula
8
-
9
- # @return [Array<ConceptSource>]
10
- attr_reader :sources
2
+ class NonVerbRep < Lutaml::Model::Serializable
3
+ attribute :image, :string
4
+ attribute :table, :string
5
+ attribute :formula, :string
6
+ attribute :sources, ConceptSource, collection: true
11
7
 
12
- def sources=(sources)
13
- @sources = sources&.map do |source|
14
- ConceptSource.new(source)
15
- end
8
+ yaml do
9
+ map :image, to: :image
10
+ map :table, to: :table
11
+ map :formula, to: :formula
12
+ map :sources, to: :sources
16
13
  end
17
14
  end
18
15
  end
@@ -1,31 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Glossarist
4
- class RelatedConcept < Model
5
- include Glossarist::Utilities::Enum
4
+ class RelatedConcept < Lutaml::Model::Serializable
5
+ attribute :content, :string
6
+ attribute :type, :string,
7
+ values: Glossarist::GlossaryDefinition::RELATED_CONCEPT_TYPES
8
+ attribute :ref, Citation
6
9
 
7
- register_enum :type, Glossarist::GlossaryDefinition::RELATED_CONCEPT_TYPES
8
-
9
- # @return [String]
10
- attr_accessor :content
11
-
12
- # Reference to the related concept.
13
- # @return [Citation]
14
- attr_reader :ref
15
-
16
- def ref=(ref)
17
- @ref = Citation.new(ref)
10
+ yaml do
11
+ map :content, to: :content
12
+ map :type, to: :type
13
+ map :ref, with: { from: :ref_from_yaml, to: :ref_to_yaml }
18
14
  end
19
15
 
20
- def to_h
21
- reference = ref&.to_h
22
- reference&.merge!(reference&.delete("ref"))
16
+ def ref_to_yaml(model, doc)
17
+ doc["ref"] = Citation.as_yaml(model.ref)["ref"] if model.ref
18
+ end
23
19
 
24
- {
25
- "type" => type.to_s,
26
- "content" => content,
27
- "ref" => reference,
28
- }.compact
20
+ def ref_from_yaml(model, value)
21
+ model.ref = Citation.of_yaml(value)
29
22
  end
30
23
  end
31
24
  end