Class: Glossarist::Concept
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dates ⇒ Object
return [Array<ConceptDate>].
-
#definition ⇒ Array<DetailedDefinition>
Concept definition.
-
#designations ⇒ Array<Designations::Base>
(also: #terms)
Concept designations.
-
#domain ⇒ String
<<BasicDocument>>LocalizedString.
-
#examples ⇒ Array<DetailedDefinition>
Concept examples.
-
#extension_attributes ⇒ Object
Contains list of extended attributes.
-
#id ⇒ String
Concept ID.
-
#lineage_source ⇒ Object
Returns the value of attribute lineage_source.
-
#lineage_source_similarity ⇒ Object
Returns the value of attribute lineage_source_similarity.
-
#non_verb_rep ⇒ NonVerbRep
Non verbal representation of the concept.
-
#notes ⇒ Array<DetailedDefinition>
Concept notes.
-
#release ⇒ Object
Returns the value of attribute release.
-
#sources ⇒ Array<ConceptSource>
List of authorative sources.
-
#subject ⇒ String
<<BasicDocument>>LocalizedString.
- #uuid ⇒ Object
Class Method Summary collapse
-
.from_h(hash) ⇒ Object
rubocop:disable Metrics/AbcSize, Style/RescueModifier.
Instance Method Summary collapse
- #authoritative_source ⇒ Object
- #authoritative_source=(sources) ⇒ Object
- #date_accepted ⇒ Object
- #date_accepted=(date) ⇒ Object
-
#initialize(*args) ⇒ Concept
constructor
A new instance of Concept.
- #normalize_args(args) ⇒ Object
- #preferred_designations ⇒ Object (also: #preferred_terms)
-
#related ⇒ Array<RelatedConcept>
All Related Concepts.
- #related=(related) ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
- #to_h_no_uuid ⇒ Object
Methods inherited from Model
new, #set_attribute, #snake_case
Constructor Details
#initialize(*args) ⇒ Concept
Returns a new instance of Concept.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/glossarist/concept.rb', line 52 def initialize(*args) @localizations = {} @sources = Glossarist::Collections::Collection.new(klass: ConceptSource) @related = Glossarist::Collections::Collection.new(klass: RelatedConcept) @definition = Glossarist::Collections::Collection.new(klass: DetailedDefinition) @notes = Glossarist::Collections::Collection.new(klass: DetailedDefinition) @examples = Glossarist::Collections::Collection.new(klass: DetailedDefinition) @dates = Glossarist::Collections::Collection.new(klass: ConceptDate) @designations = Glossarist::Collections::DesignationCollection.new @extension_attributes = {} normalize_args(args) super end |
Instance Attribute Details
#dates ⇒ Object
return [Array<ConceptDate>]
96 97 98 |
# File 'lib/glossarist/concept.rb', line 96 def dates @dates end |
#definition ⇒ Array<DetailedDefinition>
Concept definition.
30 31 32 |
# File 'lib/glossarist/concept.rb', line 30 def definition @definition end |
#designations ⇒ Array<Designations::Base> Also known as: terms
Alias terms
exists only for legacy reasons and will be removed.
Concept designations.
17 18 19 |
# File 'lib/glossarist/concept.rb', line 17 def designations @designations end |
#domain ⇒ String
<<BasicDocument>>LocalizedString
22 23 24 |
# File 'lib/glossarist/concept.rb', line 22 def domain @domain end |
#examples ⇒ Array<DetailedDefinition>
Concept examples
42 43 44 |
# File 'lib/glossarist/concept.rb', line 42 def examples @examples end |
#extension_attributes ⇒ Object
Contains list of extended attributes
45 46 47 |
# File 'lib/glossarist/concept.rb', line 45 def extension_attributes @extension_attributes end |
#id ⇒ String
Concept ID.
10 11 12 |
# File 'lib/glossarist/concept.rb', line 10 def id @id end |
#lineage_source ⇒ Object
Returns the value of attribute lineage_source.
47 48 49 |
# File 'lib/glossarist/concept.rb', line 47 def lineage_source @lineage_source end |
#lineage_source_similarity ⇒ Object
Returns the value of attribute lineage_source_similarity.
48 49 50 |
# File 'lib/glossarist/concept.rb', line 48 def lineage_source_similarity @lineage_source_similarity end |
#non_verb_rep ⇒ NonVerbRep
Non verbal representation of the concept.
34 35 36 |
# File 'lib/glossarist/concept.rb', line 34 def non_verb_rep @non_verb_rep end |
#notes ⇒ Array<DetailedDefinition>
Concept notes
38 39 40 |
# File 'lib/glossarist/concept.rb', line 38 def notes @notes end |
#release ⇒ Object
Returns the value of attribute release.
50 51 52 |
# File 'lib/glossarist/concept.rb', line 50 def release @release end |
#sources ⇒ Array<ConceptSource>
Alias authoritative_source
exists for legacy reasons and may be removed.
List of authorative sources.
93 94 95 |
# File 'lib/glossarist/concept.rb', line 93 def sources @sources end |
#subject ⇒ String
<<BasicDocument>>LocalizedString
26 27 28 |
# File 'lib/glossarist/concept.rb', line 26 def subject @subject end |
#uuid ⇒ Object
69 70 71 72 73 74 |
# File 'lib/glossarist/concept.rb', line 69 def uuid @uuid ||= Glossarist::Utilities::UUID.uuid_v5( Glossarist::Utilities::UUID::OID_NAMESPACE, to_h_no_uuid.to_yaml, ) end |
Class Method Details
.from_h(hash) ⇒ Object
rubocop:disable Metrics/AbcSize, Style/RescueModifier
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/glossarist/concept.rb', line 191 def self.from_h(hash) new.tap do |concept| concept.id = hash.dig("termid") || hash.dig("id") concept.sources = hash.dig("sources") concept. = hash.dig("related") concept.definition = hash.dig("definition") hash.values .grep(Hash) .map { |subhash| Config.class_for(:localized_concept).from_h(subhash) rescue nil } .compact concept. = hash.dig("related") || [] end end |
Instance Method Details
#authoritative_source ⇒ Object
136 137 138 |
# File 'lib/glossarist/concept.rb', line 136 def @sources.select { |source| source. } end |
#authoritative_source=(sources) ⇒ Object
140 141 142 143 144 |
# File 'lib/glossarist/concept.rb', line 140 def (sources) sources&.each do |source| @sources << source.merge({ "type" => "authoritative" }) end end |
#date_accepted ⇒ Object
156 157 158 159 |
# File 'lib/glossarist/concept.rb', line 156 def date_accepted return nil unless @dates @dates.find { |date| date.accepted? } end |
#date_accepted=(date) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/glossarist/concept.rb', line 146 def date_accepted=(date) date_hash = { "type" => "accepted", "date" => date, } @dates ||= [] @dates << ConceptDate.new(date_hash) end |
#normalize_args(args) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/glossarist/concept.rb', line 231 def normalize_args(args) args.each do |arg| data = arg.delete("data") arg.merge!(data) if data if arg["sources"] arg.delete("authoritative_source") arg.delete("authoritativeSource") end end end |
#preferred_designations ⇒ Object Also known as: preferred_terms
120 121 122 |
# File 'lib/glossarist/concept.rb', line 120 def preferred_designations @designations.select(&:preferred?) end |
#related ⇒ Array<RelatedConcept>
All Related Concepts
210 211 212 |
# File 'lib/glossarist/concept.rb', line 210 def @related.empty? ? nil : @related end |
#related=(related) ⇒ Object
214 215 216 217 |
# File 'lib/glossarist/concept.rb', line 214 def () @related.clear! &.each { |r| @related << r } end |
#to_h ⇒ Object Also known as: to_hash
182 183 184 |
# File 'lib/glossarist/concept.rb', line 182 def to_h to_h_no_uuid.merge("id" => uuid) end |
#to_h_no_uuid ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/glossarist/concept.rb', line 161 def to_h_no_uuid { "data" => { "dates" => dates&.map(&:to_h), "definition" => definition&.map(&:to_h), "examples" => examples&.map(&:to_h), "id" => id, "lineage_source_similarity" => lineage_source_similarity, "notes" => notes&.map(&:to_h), "release" => release, "sources" => sources.empty? ? nil : sources&.map(&:to_h), "terms" => (terms&.map(&:to_h) || []), "related" => &.map(&:to_h), "domain" => domain, }.compact, "date_accepted" => date_accepted&.date, }.compact end |