Class: Glossarist::GcrMetadata

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.derive_external_references(concepts) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/glossarist/gcr_metadata.rb', line 66

def self.derive_external_references(concepts)
  sources = Set.new
  concepts.each do |concept|
    concept.localizations.each do |l10n|
      l10n.data.references&.each do |ref|
        src = ref.source
        sources.add(src) if src && !src.empty?
      end
    end
  end
  sources.map { |uri| { "uri" => uri } }
end

.from_concepts(concepts, register_data: nil, options: {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/glossarist/gcr_metadata.rb', line 45

def self.from_concepts(concepts, register_data: nil, options: {})
  stats = GcrStatistics.from_concepts(concepts)
  new(
    shortname: options[:shortname] || register_data&.dig("shortname") || register_data&.dig("id"),
    version: options[:version] || register_data&.dig("version"),
    title: options[:title] || register_data&.dig("name"),
    description: options[:description] || register_data&.dig("description"),
    owner: options[:owner],
    tags: options[:tags] || [],
    concept_count: concepts.length,
    languages: stats.languages,
    created_at: Time.now.utc.iso8601,
    glossarist_version: Glossarist::VERSION,
    schema_version: register_data&.dig("schema_version") || SchemaMigration::CURRENT_SCHEMA_VERSION,
    statistics: stats,
    uri_prefix: options[:uri_prefix],
    concept_uri_template: options[:concept_uri_template],
    external_references: derive_external_references(concepts),
  )
end

Instance Method Details

#[](key) ⇒ Object



79
80
81
# File 'lib/glossarist/gcr_metadata.rb', line 79

def [](key)
  to_yaml_hash[key]
end

#dig(*keys) ⇒ Object



83
84
85
# File 'lib/glossarist/gcr_metadata.rb', line 83

def dig(*keys)
  to_yaml_hash.dig(*keys)
end