Class: Glossarist::V1::Concept

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

Constant Summary collapse

KNOWN_KEYS =
%w[termid term groups references].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_file(path) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/glossarist/v1/concept.rb', line 23

def self.from_file(path)
  return nil unless path && File.exist?(path)

  concept = from_yaml(File.read(path))
  return nil unless concept&.termid?

  concept
rescue Psych::SyntaxError, Lutaml::Model::InvalidFormatError
  nil
end

Instance Method Details

#termid?Boolean

Returns:

  • (Boolean)


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

def termid?
  !!termid && !termid.empty?
end

#to_managed_conceptObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/glossarist/v1/concept.rb', line 38

def to_managed_concept
  mc = ManagedConcept.new(data: { id: termid })

  language_blocks.each_value do |data|
    mc.add_localization(LocalizedConcept.of_yaml({ "data" => data }))
  end

  assign_references(mc) if references.is_a?(Array) && references.any?

  mc
end