Sha256: 1d9139a2383a9687ee972fa6168b9a58e3a6f265f2428d9bbf926d2360a64a7f

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

Contents

module ROCrate
  ##
  # A representation of the `ro-crate-metadata.jsonld` file.
  class Metadata < File
    IDENTIFIER = 'ro-crate-metadata.json'.freeze
    IDENTIFIER_1_0 = 'ro-crate-metadata.jsonld'.freeze # 1.0 spec identifier
    RO_CRATE_BASE = 'https://w3id.org/ro/crate/'
    CONTEXT = "#{RO_CRATE_BASE}1.1/context".freeze
    SPEC = "#{RO_CRATE_BASE}1.1".freeze

    def initialize(crate, properties = {})
      super(crate, nil, IDENTIFIER, properties)
    end

    ##
    # Generate the crate's `ro-crate-metadata.jsonld`.
    # @return [String] The rendered JSON-LD as a "prettified" string.
    def generate
      graph = crate.entities.map(&:properties).reject(&:empty?)
      JSON.pretty_generate('@context' => CONTEXT, '@graph' => graph)
    end

    private

    def source
      Entry.new(StringIO.new(generate))
    end

    def default_properties
      {
        '@id' => IDENTIFIER,
        '@type' => 'CreativeWork',
        'about' => { '@id' => crate.id },
        'conformsTo' => { '@id' => SPEC }
      }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ro-crate-0.4.10 lib/ro_crate/model/metadata.rb
ro-crate-0.4.9 lib/ro_crate/model/metadata.rb
ro-crate-0.4.8 lib/ro_crate/model/metadata.rb
ro-crate-0.4.7 lib/ro_crate/model/metadata.rb
ro-crate-0.4.6 lib/ro_crate/model/metadata.rb
ro-crate-0.4.5 lib/ro_crate/model/metadata.rb
ro-crate-0.4.4 lib/ro_crate/model/metadata.rb
ro-crate-0.4.3 lib/ro_crate/model/metadata.rb
ro-crate-0.4.2 lib/ro_crate/model/metadata.rb
ro-crate-0.4.1 lib/ro_crate/model/metadata.rb
ro-crate-0.4.0 lib/ro_crate/model/metadata.rb