Class: Glossarist::ManagedConcept
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Glossarist::ManagedConcept
show all
- Includes:
- Utilities::CommonFunctions
- Defined in:
- lib/glossarist/managed_concept.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#convert_keys_to_snake_case, #slice_keys, #snake_case, #stringify_keys, #symbolize_keys
Class Method Details
.detect_schema_version(concept) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/glossarist/managed_concept.rb', line 168
def self.detect_schema_version(concept) raw = concept.schema_version
if raw && !%w[legacy nil].include?(raw.to_s)
return raw.to_s
end
return "3" if concept.related&.any?
return "3" if concept.sources&.any?
return "3" if concept.data&.domains&.any?
return "3" if localization_has_references?(concept)
"2"
end
|
.localization_has_references?(concept) ⇒ Boolean
182
183
184
185
186
|
# File 'lib/glossarist/managed_concept.rb', line 182
def self.localization_has_references?(concept)
concept.localizations&.any? do |l10n|
l10n.is_a?(LocalizedConcept) && l10n.data&.references&.any?
end
end
|
Instance Method Details
#add_localization(localized_concept) ⇒ Object
Also known as:
add_l10n
Adds concept localization.
112
113
114
115
116
117
118
119
|
# File 'lib/glossarist/managed_concept.rb', line 112
def add_localization(localized_concept)
lang = localized_concept.language_code
data.localized_concepts ||= {}
data.localized_concepts[lang] =
data.localized_concepts[lang] || localized_concept.uuid
localized_concept.uuid = data.localized_concepts[lang]
localizations.store(lang, localized_concept)
end
|
#all_sources ⇒ Object
147
148
149
150
151
152
|
# File 'lib/glossarist/managed_concept.rb', line 147
def all_sources
list = Array(sources)
list.concat(Array(data&.sources))
localizations.each_value { |l10n| list.concat(l10n.all_sources) }
list
end
|
#assign_uuid(new_uuid) ⇒ Object
164
165
166
|
# File 'lib/glossarist/managed_concept.rb', line 164
def assign_uuid(new_uuid)
@uuid = new_uuid
end
|
#date_accepted_from_yaml(model, value) ⇒ Object
50
51
52
53
54
|
# File 'lib/glossarist/managed_concept.rb', line 50
def date_accepted_from_yaml(model, value)
model.date_accepted = ConceptDate.of_yaml(
{ "date" => value, "type" => "accepted" },
)
end
|
#date_accepted_to_yaml(model, doc) ⇒ Object
56
57
58
59
60
|
# File 'lib/glossarist/managed_concept.rb', line 56
def date_accepted_to_yaml(model, doc)
if model.date_accepted
doc["date_accepted"] = model.date_accepted.date.iso8601
end
end
|
#default_definition ⇒ Object
138
139
140
141
|
# File 'lib/glossarist/managed_concept.rb', line 138
def default_definition
localized = localization("eng") || localizations.values.first
localized&.data&.definition&.first&.content
end
|
#default_designation ⇒ Object
132
133
134
135
136
|
# File 'lib/glossarist/managed_concept.rb', line 132
def default_designation
localized = localization("eng") || localizations.values.first
terms = localized&.preferred_terms&.first || localized&.terms&.first
terms&.designation
end
|
#default_lang ⇒ Object
143
144
145
|
# File 'lib/glossarist/managed_concept.rb', line 143
def default_lang
localization("eng") || localizations.values.first
end
|
#find_source_by_id(id) ⇒ Object
154
155
156
157
158
|
# File 'lib/glossarist/managed_concept.rb', line 154
def find_source_by_id(id)
return nil if id.nil? || id.to_s.strip.empty?
all_sources.find { |source| source.id == id }
end
|
#identifier_from_yaml(model, value) ⇒ Object
82
83
84
|
# File 'lib/glossarist/managed_concept.rb', line 82
def identifier_from_yaml(model, value)
model.identifier = value || model.identifier
end
|
#identifier_to_yaml(model, doc) ⇒ Object
77
78
79
80
|
# File 'lib/glossarist/managed_concept.rb', line 77
def identifier_to_yaml(model, doc)
value = model.identifier || model.id
doc["id"] = value if value && !doc["id"]
end
|
#localization(lang) ⇒ Object
Also known as:
l10n
45
46
47
|
# File 'lib/glossarist/managed_concept.rb', line 45
def localization(lang)
localizations[lang]
end
|
#localizations ⇒ Object
41
42
43
|
# File 'lib/glossarist/managed_concept.rb', line 41
def localizations
data.localizations
end
|
#localized_concepts ⇒ Object
106
107
108
|
# File 'lib/glossarist/managed_concept.rb', line 106
def localized_concepts
data.localized_concepts
end
|
#localized_concepts=(localized_concepts_collection) ⇒ Object
rubocop:disable Metrics/AbcSize
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/glossarist/managed_concept.rb', line 86
def localized_concepts=(localized_concepts_collection) return unless localized_concepts_collection
if localized_concepts_collection.is_a?(Hash)
data.localized_concepts = stringify_keys(localized_concepts_collection)
else
localized_concepts_collection.each do |localized_concept_hash|
lang = localized_concept_hash.dig("data", "language_code").to_s
localized_concept = add_localization(
Config.class_for(:localized_concept).of_yaml(localized_concept_hash),
)
data.localized_concepts[lang] = localization(lang).uuid
localized_concept
end
end
end
|
#schema_version ⇒ Object
160
161
162
|
# File 'lib/glossarist/managed_concept.rb', line 160
def schema_version
@schema_version
end
|
#uuid_from_yaml(model, value) ⇒ Object
66
67
68
|
# File 'lib/glossarist/managed_concept.rb', line 66
def uuid_from_yaml(model, value)
model.uuid = value if value
end
|
#uuid_to_yaml(model, doc) ⇒ Object
62
63
64
|
# File 'lib/glossarist/managed_concept.rb', line 62
def uuid_to_yaml(model, doc)
doc["id"] = model.uuid if model.uuid
end
|