Class: Glossarist::ManagedConcept
Instance Attribute Summary collapse
Instance Method Summary
collapse
#slice_keys, #symbolize_keys
extended, included
Methods inherited from Model
from_h, new, #set_attribute
Constructor Details
#initialize(attributes = {}) ⇒ ManagedConcept
Returns a new instance of ManagedConcept.
30
31
32
33
34
35
36
|
# File 'lib/glossarist/managed_concept.rb', line 30
def initialize(attributes = {})
@localizations = {}
self.localized_concepts = attributes.values.grep(Hash)
attributes = symbolize_keys(attributes)
super(slice_keys(attributes, managed_concept_attributes))
end
|
Instance Attribute Details
#dates ⇒ Object
return [Array<ConceptDate>]
19
20
21
|
# File 'lib/glossarist/managed_concept.rb', line 19
def dates
@dates
end
|
#id ⇒ String
9
10
11
|
# File 'lib/glossarist/managed_concept.rb', line 9
def id
@id
end
|
All localizations for this concept.
Keys are language codes and values are instances of LocalizedConcept.
28
29
30
|
# File 'lib/glossarist/managed_concept.rb', line 28
def localizations
@localizations
end
|
#localized_concepts ⇒ Object
return [Array<LocalizedConcept>]
22
23
24
|
# File 'lib/glossarist/managed_concept.rb', line 22
def localized_concepts
@localized_concepts
end
|
13
14
15
|
# File 'lib/glossarist/managed_concept.rb', line 13
def related
@related
end
|
Instance Method Details
#add_localization(localized_concept) ⇒ Object
Also known as:
add_l10n
Adds concept localization.
58
59
60
61
|
# File 'lib/glossarist/managed_concept.rb', line 58
def add_localization(localized_concept)
lang = localized_concept.language_code
localizations.store(lang, localized_concept)
end
|
#default_definition ⇒ Object
88
89
90
91
|
# File 'lib/glossarist/managed_concept.rb', line 88
def default_definition
localized = localization("eng") || localizations.values.first
localized&.definition&.first&.content
end
|
#default_designation ⇒ Object
83
84
85
86
|
# File 'lib/glossarist/managed_concept.rb', line 83
def default_designation
localized = localization("eng") || localizations.values.first
localized&.terms&.first&.designation
end
|
#default_lang ⇒ Object
93
94
95
|
# File 'lib/glossarist/managed_concept.rb', line 93
def default_lang
localization("eng") || localizations.values.first
end
|
#localization(lang) ⇒ LocalizedConcept
Also known as:
l10n
Returns concept localization.
68
69
70
|
# File 'lib/glossarist/managed_concept.rb', line 68
def localization(lang)
localizations[lang]
end
|
#managed_concept_attributes ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/glossarist/managed_concept.rb', line 97
def managed_concept_attributes
%i[
id
termid
related
status
dates
localized_concepts
].compact
end
|
#to_h ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/glossarist/managed_concept.rb', line 74
def to_h
{
"termid" => id,
"term" => default_designation,
"related" => related&.map(&:to_h),
"dates" => dates&.empty? ? nil : dates&.map(&:to_h),
}.merge(localizations.transform_values(&:to_h)).compact
end
|