Class: Glossarist::Concept

Inherits:
Model
  • Object
show all
Defined in:
lib/glossarist/concept.rb

Direct Known Subclasses

LocalizedConcept

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

new, #set_attribute

Constructor Details

#initializeConcept

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

#datesObject

return [Array<ConceptDate>]



65
66
67
# File 'lib/glossarist/concept.rb', line 65

def dates
  @dates
end

#definitionArray<DetailedDefinition>

Concept definition.

Returns:



29
30
31
# File 'lib/glossarist/concept.rb', line 29

def definition
  @definition
end

#designationsArray<Designations::Base> Also known as: terms

TODO:

Alias terms exists only for legacy reasons and will be removed.

Concept designations.

Returns:

  • (Array<Designations::Base>)


16
17
18
# File 'lib/glossarist/concept.rb', line 16

def designations
  @designations
end

#domainString

<<BasicDocument>>LocalizedString

Returns:

  • (String)


21
22
23
# File 'lib/glossarist/concept.rb', line 21

def domain
  @domain
end

#examplesArray<DetailedDefinition>

Concept examples

Returns:



41
42
43
# File 'lib/glossarist/concept.rb', line 41

def examples
  @examples
end

#extension_attributesObject

Contains list of extended attributes



44
45
46
# File 'lib/glossarist/concept.rb', line 44

def extension_attributes
  @extension_attributes
end

#idString

Concept ID.

Returns:

  • (String)


10
11
12
# File 'lib/glossarist/concept.rb', line 10

def id
  @id
end

#non_verb_repNonVerbRep

Non verbal representation of the concept.

Returns:



33
34
35
# File 'lib/glossarist/concept.rb', line 33

def non_verb_rep
  @non_verb_rep
end

#notesArray<DetailedDefinition>

Concept notes

Returns:



37
38
39
# File 'lib/glossarist/concept.rb', line 37

def notes
  @notes
end

#sourcesArray<ConceptSource> Also known as: authoritative_source

TODO:

Alias authoritative_source exists for legacy reasons and may be removed.

List of authorative sources.

Returns:



61
62
63
# File 'lib/glossarist/concept.rb', line 61

def sources
  @sources
end

#subjectString

<<BasicDocument>>LocalizedString

Returns:

  • (String)


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.related = 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.related = 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 authoritative_source=(sources)
  self.sources = sources&.map do |source|
    source.merge({ "type" => "authoritative" })
  end
end

All Related Concepts

Returns:



139
140
141
# File 'lib/glossarist/concept.rb', line 139

def related
  @related.empty? ? nil : @related
end

#related=(related) ⇒ Object



143
144
145
# File 'lib/glossarist/concept.rb', line 143

def related=(related)
  @related = related&.map { |r| RelatedConcept.new(r) } || []
end

#to_hObject 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" => 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