Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

![Tests](https://github.com/ResearchObject/ro-crate-ruby/actions/workflows/tests.yml/badge.svg)

This is a WIP gem for creating, manipulating and reading RO-Crates (conforming to version 1.2 of the specification). RO-Crates produced by older versions (1.0, 1.1) of the spec can still be read.
This is a WIP gem for creating, manipulating and reading RO-Crates (conforming to version 1.3 of the specification). RO-Crates produced by older versions (1.0, 1.1, 1.2) of the spec can still be read.

* RO-Crate - https://www.researchobject.org/ro-crate/
* RO-Crate spec (1.2) - https://www.researchobject.org/ro-crate/specification/1.2/
* RO-Crate spec (1.3) - https://www.researchobject.org/ro-crate/specification/1.3/

## Installation

Expand Down
4 changes: 2 additions & 2 deletions lib/ro_crate/model/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Metadata < File
IDENTIFIER_1_0 = 'ro-crate-metadata.jsonld'.freeze # 1.0 spec identifier
RO_CRATE_BASE = 'https://w3id.org/ro/crate/'

SUPPORTED_VERSIONS = %w[1.0 1.0-DRAFT 1.1 1.1-DRAFT 1.2 1.2-DRAFT].freeze
DEFAULT_VERSION = '1.2'.freeze
SUPPORTED_VERSIONS = %w[1.0 1.0-DRAFT 1.1 1.1-DRAFT 1.2 1.2-DRAFT 1.3].freeze
DEFAULT_VERSION = '1.3'.freeze

CONTEXT = "#{RO_CRATE_BASE}#{DEFAULT_VERSION}/context".freeze
SPEC = "#{RO_CRATE_BASE}#{DEFAULT_VERSION}".freeze
Expand Down
10 changes: 5 additions & 5 deletions test/crate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ class CrateTest < Test::Unit::TestCase
assert crate.get('#joehouse')
end

test 'defaults to RO-Crate spec 1.2' do
test 'defaults to RO-Crate spec 1.3' do
crate = ROCrate::Crate.new
assert_equal '1.2', crate.metadata.version
assert_equal 'https://w3id.org/ro/crate/1.2/context', crate.metadata.context
assert_equal 'https://w3id.org/ro/crate/1.2', crate.metadata.spec_url
assert_equal({ '@id' => 'https://w3id.org/ro/crate/1.2' }, crate.metadata.properties['conformsTo'])
assert_equal '1.3', crate.metadata.version
assert_equal 'https://w3id.org/ro/crate/1.3/context', crate.metadata.context
assert_equal 'https://w3id.org/ro/crate/1.3', crate.metadata.spec_url
assert_equal({ '@id' => 'https://w3id.org/ro/crate/1.3' }, crate.metadata.properties['conformsTo'])
end

test 'can write older spec version' do
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/crate-spec1.2/file with spaces.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I have spaces in my name
42 changes: 42 additions & 0 deletions test/fixtures/crate-spec1.2/ro-crate-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"@context": "https://w3id.org/ro/crate/1.2/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {
"@id": "./"
},
"conformsTo": {
"@id": "https://w3id.org/ro/crate/1.2"
}
},
{
"@id": "ro-crate-preview.html",
"@type": "CreativeWork",
"about": {
"@id": "./"
}
},
{
"@id": "./",
"@type": "Dataset",
"hasPart": [
{
"@id": "http://example.com/external_ref.txt"
},
{
"@id": "file%20with%20spaces.txt"
}
]
},
{
"@id": "http://example.com/external_ref.txt",
"@type": "File"
},
{
"@id": "file%20with%20spaces.txt",
"@type": "File"
}
]
}
82 changes: 82 additions & 0 deletions test/fixtures/crate-spec1.2/ro-crate-preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

<!DOCTYPE html>
<html lang="en">
<head>
<title>New RO-Crate</title>
<script type="application/ld+json">{
"@context": "https://w3id.org/ro/crate/1.2/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {
"@id": "./"
},
"conformsTo": {
"@id": "https://w3id.org/ro/crate/1.2"
}
},
{
"@id": "ro-crate-preview.html",
"@type": "CreativeWork",
"about": {
"@id": "./"
}
},
{
"@id": "./",
"@type": "Dataset",
"hasPart": [
{
"@id": "http://example.com/external_ref.txt"
},
{
"@id": "file%20with%20spaces.txt"
}
]
},
{
"@id": "http://example.com/external_ref.txt",
"@type": "File"
},
{
"@id": "file%20with%20spaces.txt",
"@type": "File"
}
]
}</script>
<meta name="generator" content="https://github.com/ResearchObject/ro-crate-ruby">
<meta name="keywords" content="RO-Crate">
<meta charset="utf-8">
</head>
<body>
<h1>New RO-Crate</h1>

<p>

</p>
<dl>




</dl>

<h2>Contents</h2>
<ul>

<li>
<strong><a href="http://example.com/external_ref.txt" target="_blank">http://example.com/external_ref.txt</a></strong>


</li>

<li>
<strong>file%20with%20spaces.txt</strong>


</li>

</ul>
</body>
</html>
1 change: 1 addition & 0 deletions test/fixtures/crate-spec1.3/file with spaces.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I have spaces in my name
42 changes: 42 additions & 0 deletions test/fixtures/crate-spec1.3/ro-crate-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"@context": "https://w3id.org/ro/crate/1.3/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {
"@id": "./"
},
"conformsTo": {
"@id": "https://w3id.org/ro/crate/1.3"
}
},
{
"@id": "ro-crate-preview.html",
"@type": "CreativeWork",
"about": {
"@id": "./"
}
},
{
"@id": "./",
"@type": "Dataset",
"hasPart": [
{
"@id": "http://example.com/external_ref.txt"
},
{
"@id": "file%20with%20spaces.txt"
}
]
},
{
"@id": "http://example.com/external_ref.txt",
"@type": "File"
},
{
"@id": "file%20with%20spaces.txt",
"@type": "File"
}
]
}
82 changes: 82 additions & 0 deletions test/fixtures/crate-spec1.3/ro-crate-preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

<!DOCTYPE html>
<html lang="en">
<head>
<title>New RO-Crate</title>
<script type="application/ld+json">{
"@context": "https://w3id.org/ro/crate/1.3/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {
"@id": "./"
},
"conformsTo": {
"@id": "https://w3id.org/ro/crate/1.3"
}
},
{
"@id": "ro-crate-preview.html",
"@type": "CreativeWork",
"about": {
"@id": "./"
}
},
{
"@id": "./",
"@type": "Dataset",
"hasPart": [
{
"@id": "http://example.com/external_ref.txt"
},
{
"@id": "file%20with%20spaces.txt"
}
]
},
{
"@id": "http://example.com/external_ref.txt",
"@type": "File"
},
{
"@id": "file%20with%20spaces.txt",
"@type": "File"
}
]
}</script>
<meta name="generator" content="https://github.com/ResearchObject/ro-crate-ruby">
<meta name="keywords" content="RO-Crate">
<meta charset="utf-8">
</head>
<body>
<h1>New RO-Crate</h1>

<p>

</p>
<dl>




</dl>

<h2>Contents</h2>
<ul>

<li>
<strong><a href="http://example.com/external_ref.txt" target="_blank">http://example.com/external_ref.txt</a></strong>


</li>

<li>
<strong>file%20with%20spaces.txt</strong>


</li>

</ul>
</body>
</html>
42 changes: 42 additions & 0 deletions test/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,48 @@ class ReaderTest < Test::Unit::TestCase
assert crate.preview.source.source.is_a?(ROCrate::PreviewGenerator)
end

test 'can read a 1.2 spec crate' do
stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')

crate = ROCrate::Reader.read_directory(fixture_file('crate-spec1.1').path)
file = crate.dereference('file with spaces.txt')
Comment thread
fbacall marked this conversation as resolved.
Outdated
assert file
assert file.is_a?(ROCrate::File)
refute file.remote?
assert file.source.is_a?(ROCrate::Entry)
assert_equal 'file%20with%20spaces.txt', file.id

ext_file = crate.dereference('http://example.com/external_ref.txt')
assert ext_file
assert ext_file.is_a?(ROCrate::File)
assert ext_file.remote?
assert ext_file.source.is_a?(ROCrate::RemoteEntry)
assert_equal 'http://example.com/external_ref.txt', ext_file.id
assert_equal 'file contents', ext_file.source.read
assert crate.preview.source.source.is_a?(ROCrate::PreviewGenerator)
Comment thread
fbacall marked this conversation as resolved.
Outdated
end

test 'can read a 1.3 spec crate' do
stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')

crate = ROCrate::Reader.read_directory(fixture_file('crate-spec1.1').path)
file = crate.dereference('file with spaces.txt')
Comment thread
fbacall marked this conversation as resolved.
Outdated
assert file
assert file.is_a?(ROCrate::File)
refute file.remote?
assert file.source.is_a?(ROCrate::Entry)
assert_equal 'file%20with%20spaces.txt', file.id

ext_file = crate.dereference('http://example.com/external_ref.txt')
assert ext_file
assert ext_file.is_a?(ROCrate::File)
assert ext_file.remote?
assert ext_file.source.is_a?(ROCrate::RemoteEntry)
assert_equal 'http://example.com/external_ref.txt', ext_file.id
assert_equal 'file contents', ext_file.source.read
assert crate.preview.source.source.is_a?(ROCrate::PreviewGenerator)
Comment thread
fbacall marked this conversation as resolved.
Outdated
end

test 'reading from directory with unlisted files' do
crate = ROCrate::Reader.read_directory(fixture_file('sparse_directory_crate').path)

Expand Down