Class: ROCrate::Metadata

Inherits:
File show all
Defined in:
lib/ro_crate/model/metadata.rb

Overview

A representation of the ‘ro-crate-metadata.jsonld` file.

Constant Summary collapse

IDENTIFIER =
'ro-crate-metadata.json'.freeze
IDENTIFIER_1_0 =

1.0 spec identifier

'ro-crate-metadata.jsonld'.freeze
RO_CRATE_BASE =
'https://w3id.org/ro/crate/'
CONTEXT =
"#{RO_CRATE_BASE}1.1/context".freeze
SPEC =
"#{RO_CRATE_BASE}1.1".freeze

Instance Attribute Summary

Attributes inherited from Entity

#crate, #properties

Instance Method Summary collapse

Methods inherited from File

format_local_id, #payload, #remote?

Methods inherited from DataEntity

#filepath, #payload, specialize

Methods inherited from Entity

#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #delete, #dereference, #eql?, #external?, format_id, format_local_id, #has_type?, #hash, #id, #id=, #inspect, #linked_entities, properties, #raw_properties, #reference, #to_json, #type, #type=

Constructor Details

#initialize(crate, properties = {}) ⇒ Metadata

Returns a new instance of Metadata.



11
12
13
# File 'lib/ro_crate/model/metadata.rb', line 11

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

Instance Method Details

#contextObject



23
24
25
# File 'lib/ro_crate/model/metadata.rb', line 23

def context
  @context || CONTEXT
end

#context=(c) ⇒ Object



27
28
29
# File 'lib/ro_crate/model/metadata.rb', line 27

def context= c
  @context = c
end

#generateString

Generate the crate’s ‘ro-crate-metadata.jsonld`.

Returns:

  • (String)

    The rendered JSON-LD as a “prettified” string.



18
19
20
21
# File 'lib/ro_crate/model/metadata.rb', line 18

def generate
  graph = crate.entities.map(&:properties).reject(&:empty?)
  JSON.pretty_generate('@context' => context, '@graph' => graph)
end