Class: Glossarist::GcrMetadata

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

Class Method Summary collapse

Class Method Details

.derive_external_references(concepts) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/glossarist/gcr_metadata.rb', line 70

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



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

def self.from_concepts(concepts, register_data: nil, options: {})
  stats = GcrStatistics.from_concepts(concepts)
  rd = register_data
  new(
    shortname: options[:shortname] || rd&.[]("shortname") || rd&.[]("id"),
    version: options[:version] || rd&.[]("version"),
    title: options[:title] || rd&.[]("name"),
    description: options[:description] || rd&.[]("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: rd&.[]("schema_version") || SchemaMigration::CURRENT_SCHEMA_VERSION,
    statistics: stats,
    uri_prefix: options[:uri_prefix],
    concept_uri_template: options[:concept_uri_template],
    compiled_formats: options[:compiled_formats] || [],
    external_references: derive_external_references(concepts),
  )
end