Sha256: 3e2bc193fced3a34df8cb4466a3f905ec42901cb0ff9d03bce661920a947f0ae

Contents?: true

Size: 1.36 KB

Versions: 21

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Commonmeta
  module Writers
    module CodemetaWriter
      def codemeta
        return nil unless valid? || show_errors
        
        authors = Array.wrap(contributors).select { |c| c['contributorRoles'] == ['Author'] }
        
        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' => to_schema_org(authors),
          '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
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
commonmeta-ruby-3.13 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.12.1 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.12.0 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.11.0 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.9.0 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.8.3 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.8.2 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.8.1 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.8.0 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.7.3 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.7.2 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.7.1 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.7.0 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.6.1 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.6 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.5.5 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.5.4 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.5.3 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.5.2 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.5.1 lib/commonmeta/writers/codemeta_writer.rb