Module: Commonmeta::Writers::CodemetaWriter

Included in:
MetadataUtils
Defined in:
lib/commonmeta/writers/codemeta_writer.rb

Instance Method Summary collapse

Instance Method Details

#codemetaObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/commonmeta/writers/codemeta_writer.rb', line 6

def codemeta
  return nil unless valid? || show_errors

  hsh = {
    '@context' => id.present? ? 'https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld' : nil,
    '@type' => Commonmeta::Utils::CM_TO_SO_TRANSLATIONS.fetch(type, 'SoftwareSourceCode'),
    '@id' => normalize_id(id),
    'identifier' => to_schema_org_identifiers(alternate_identifiers),
    'codeRepository' => url,
    'name' => parse_attributes(titles, content: 'title', first: true),
    'authors' => creators,
    'description' => parse_attributes(descriptions, content: 'description', first: true),
    'version' => version,
    'tags' => if subjects.present?
                Array.wrap(subjects).map do |k|
                  parse_attributes(k, content: 'subject', first: true)
                end
              end,
    'datePublished' => date['published'],
    'dateModified' => date['updated'],
    'publisher' => publisher['name'],
    'license' => license.to_h['id']
  }.compact
  JSON.pretty_generate hsh.presence
end