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.
-
#non_verb_rep ⇒ NonVerbRep
Non verbal representation of the concept.
-
#notes ⇒ Array<DetailedDefinition>
Concept notes.
-
#sources ⇒ Array<ConceptSource>
(also: #authoritative_source)
List of authorative sources.
-
#subject ⇒ String
<<BasicDocument>>LocalizedString.
Class Method Summary collapse
-
.from_h(hash) ⇒ Object
rubocop:disable Metrics/AbcSize, Style/RescueModifier.
Instance Method Summary collapse
- #authoritative_source=(sources) ⇒ Object
-
#initialize ⇒ Concept
constructor
A new instance of Concept.
-
#related ⇒ Array<RelatedConcept>
All Related Concepts.
- #related=(related) ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
Methods inherited from Model
Constructor Details
#initialize ⇒ Concept
Returns a new instance of Concept.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/glossarist/concept.rb', line 46 def initialize(*) @localizations = {} @sources = [] @related = [] @notes = [] @designations = [] @extension_attributes = {} super end |
Instance Attribute Details
#dates ⇒ Object
return [Array<ConceptDate>]
65 66 67 |
# File 'lib/glossarist/concept.rb', line 65 def dates @dates end |
#definition ⇒ Array<DetailedDefinition>
Concept definition.
29 30 31 |
# File 'lib/glossarist/concept.rb', line 29 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.
16 17 18 |
# File 'lib/glossarist/concept.rb', line 16 def designations @designations end |
#domain ⇒ String
<<BasicDocument>>LocalizedString
21 22 23 |
# File 'lib/glossarist/concept.rb', line 21 def domain @domain end |
#examples ⇒ Array<DetailedDefinition>
Concept examples
41 42 43 |
# File 'lib/glossarist/concept.rb', line 41 def examples @examples end |
#extension_attributes ⇒ Object
Contains list of extended attributes
44 45 46 |
# File 'lib/glossarist/concept.rb', line 44 def extension_attributes @extension_attributes end |
#id ⇒ String
Concept ID.
10 11 12 |
# File 'lib/glossarist/concept.rb', line 10 def id @id end |
#non_verb_rep ⇒ NonVerbRep
Non verbal representation of the concept.
33 34 35 |
# File 'lib/glossarist/concept.rb', line 33 def non_verb_rep @non_verb_rep end |
#notes ⇒ Array<DetailedDefinition>
Concept notes
37 38 39 |
# File 'lib/glossarist/concept.rb', line 37 def notes @notes end |
#sources ⇒ Array<ConceptSource> Also known as:
Alias authoritative_source
exists for legacy reasons and may be removed.
List of authorative sources.
61 62 63 |
# File 'lib/glossarist/concept.rb', line 61 def sources @sources end |
#subject ⇒ String
<<BasicDocument>>LocalizedString
25 26 27 |
# File 'lib/glossarist/concept.rb', line 25 def subject @subject end |
Class Method Details
.from_h(hash) ⇒ Object
rubocop:disable Metrics/AbcSize, Style/RescueModifier
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/glossarist/concept.rb', line 120 def self.from_h(hash) new.tap do |concept| concept.id = hash.dig("termid") 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=(sources) ⇒ Object
97 98 99 100 101 |
# File 'lib/glossarist/concept.rb', line 97 def (sources) self.sources = sources&.map do |source| source.merge({ "type" => "authoritative" }) end end |
#related ⇒ Array<RelatedConcept>
All Related Concepts
139 140 141 |
# File 'lib/glossarist/concept.rb', line 139 def @related.empty? ? nil : @related end |
#related=(related) ⇒ Object
143 144 145 |
# File 'lib/glossarist/concept.rb', line 143 def () @related = &.map { |r| RelatedConcept.new(r) } || [] end |
#to_h ⇒ Object Also known as: to_hash
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/glossarist/concept.rb', line 103 def to_h { "id" => id, "related" => &.map(&:to_h), "terms" => (terms&.map(&:to_h) || []), "definition" => definition&.map(&:to_h), "notes" => notes&.map(&:to_h), "examples" => examples&.map(&:to_h), } .compact end |