Sha256: 83db339491987feeb24b87854813db60c89577ead757fa4abfa8c01815ca1afb

Contents?: true

Size: 1.24 KB

Versions: 52

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Commonmeta
  module Writers
    module CodemetaWriter
      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
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
commonmeta-ruby-3.4.5 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.4.4 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.4.3 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.4.2 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.4.1 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.4.0 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.18 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.17 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.16 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.15 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.14 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.13 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.12 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.11 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.10 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.9 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.8 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.7 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.6 lib/commonmeta/writers/codemeta_writer.rb
commonmeta-ruby-3.3.5 lib/commonmeta/writers/codemeta_writer.rb