Skip to content

Commit 86b93e9

Browse files
authored
Merge pull request #42 from ResearchObject/ro-crate1.3
Support RO-Crate 1.3
2 parents 4a7e752 + 864df95 commit 86b93e9

10 files changed

Lines changed: 301 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

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

5-
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.
5+
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.
66

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

1010
## Installation
1111

lib/ro_crate/model/metadata.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Metadata < File
66
IDENTIFIER_1_0 = 'ro-crate-metadata.jsonld'.freeze # 1.0 spec identifier
77
RO_CRATE_BASE = 'https://w3id.org/ro/crate/'
88

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

1212
CONTEXT = "#{RO_CRATE_BASE}#{DEFAULT_VERSION}/context".freeze
1313
SPEC = "#{RO_CRATE_BASE}#{DEFAULT_VERSION}".freeze

test/crate_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ class CrateTest < Test::Unit::TestCase
378378
assert crate.get('#joehouse')
379379
end
380380

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

389389
test 'can write older spec version' do
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I have spaces in my name
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"@context": "https://w3id.org/ro/crate/1.2/context",
3+
"@graph": [
4+
{
5+
"@id": "ro-crate-metadata.json",
6+
"@type": "CreativeWork",
7+
"about": {
8+
"@id": "./"
9+
},
10+
"conformsTo": {
11+
"@id": "https://w3id.org/ro/crate/1.2"
12+
}
13+
},
14+
{
15+
"@id": "ro-crate-preview.html",
16+
"@type": "CreativeWork",
17+
"about": {
18+
"@id": "./"
19+
}
20+
},
21+
{
22+
"@id": "./",
23+
"@type": "Dataset",
24+
"hasPart": [
25+
{
26+
"@id": "http://example.com/external_ref.txt"
27+
},
28+
{
29+
"@id": "file%20with%20spaces.txt"
30+
}
31+
]
32+
},
33+
{
34+
"@id": "http://example.com/external_ref.txt",
35+
"@type": "File"
36+
},
37+
{
38+
"@id": "file%20with%20spaces.txt",
39+
"@type": "File"
40+
}
41+
]
42+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<title>New RO-Crate</title>
6+
<script type="application/ld+json">{
7+
"@context": "https://w3id.org/ro/crate/1.2/context",
8+
"@graph": [
9+
{
10+
"@id": "ro-crate-metadata.json",
11+
"@type": "CreativeWork",
12+
"about": {
13+
"@id": "./"
14+
},
15+
"conformsTo": {
16+
"@id": "https://w3id.org/ro/crate/1.2"
17+
}
18+
},
19+
{
20+
"@id": "ro-crate-preview.html",
21+
"@type": "CreativeWork",
22+
"about": {
23+
"@id": "./"
24+
}
25+
},
26+
{
27+
"@id": "./",
28+
"@type": "Dataset",
29+
"hasPart": [
30+
{
31+
"@id": "http://example.com/external_ref.txt"
32+
},
33+
{
34+
"@id": "file%20with%20spaces.txt"
35+
}
36+
]
37+
},
38+
{
39+
"@id": "http://example.com/external_ref.txt",
40+
"@type": "File"
41+
},
42+
{
43+
"@id": "file%20with%20spaces.txt",
44+
"@type": "File"
45+
}
46+
]
47+
}</script>
48+
<meta name="generator" content="https://github.com/ResearchObject/ro-crate-ruby">
49+
<meta name="keywords" content="RO-Crate">
50+
<meta charset="utf-8">
51+
</head>
52+
<body>
53+
<h1>New RO-Crate</h1>
54+
55+
<p>
56+
57+
</p>
58+
<dl>
59+
60+
61+
62+
63+
</dl>
64+
65+
<h2>Contents</h2>
66+
<ul>
67+
68+
<li>
69+
<strong><a href="http://example.com/external_ref.txt" target="_blank">http://example.com/external_ref.txt</a></strong>
70+
71+
72+
</li>
73+
74+
<li>
75+
<strong>file%20with%20spaces.txt</strong>
76+
77+
78+
</li>
79+
80+
</ul>
81+
</body>
82+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I have spaces in my name
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"@context": "https://w3id.org/ro/crate/1.3/context",
3+
"@graph": [
4+
{
5+
"@id": "ro-crate-metadata.json",
6+
"@type": "CreativeWork",
7+
"about": {
8+
"@id": "./"
9+
},
10+
"conformsTo": {
11+
"@id": "https://w3id.org/ro/crate/1.3"
12+
}
13+
},
14+
{
15+
"@id": "ro-crate-preview.html",
16+
"@type": "CreativeWork",
17+
"about": {
18+
"@id": "./"
19+
}
20+
},
21+
{
22+
"@id": "./",
23+
"@type": "Dataset",
24+
"hasPart": [
25+
{
26+
"@id": "http://example.com/external_ref.txt"
27+
},
28+
{
29+
"@id": "file%20with%20spaces.txt"
30+
}
31+
]
32+
},
33+
{
34+
"@id": "http://example.com/external_ref.txt",
35+
"@type": "File"
36+
},
37+
{
38+
"@id": "file%20with%20spaces.txt",
39+
"@type": "File"
40+
}
41+
]
42+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<title>New RO-Crate</title>
6+
<script type="application/ld+json">{
7+
"@context": "https://w3id.org/ro/crate/1.3/context",
8+
"@graph": [
9+
{
10+
"@id": "ro-crate-metadata.json",
11+
"@type": "CreativeWork",
12+
"about": {
13+
"@id": "./"
14+
},
15+
"conformsTo": {
16+
"@id": "https://w3id.org/ro/crate/1.3"
17+
}
18+
},
19+
{
20+
"@id": "ro-crate-preview.html",
21+
"@type": "CreativeWork",
22+
"about": {
23+
"@id": "./"
24+
}
25+
},
26+
{
27+
"@id": "./",
28+
"@type": "Dataset",
29+
"hasPart": [
30+
{
31+
"@id": "http://example.com/external_ref.txt"
32+
},
33+
{
34+
"@id": "file%20with%20spaces.txt"
35+
}
36+
]
37+
},
38+
{
39+
"@id": "http://example.com/external_ref.txt",
40+
"@type": "File"
41+
},
42+
{
43+
"@id": "file%20with%20spaces.txt",
44+
"@type": "File"
45+
}
46+
]
47+
}</script>
48+
<meta name="generator" content="https://github.com/ResearchObject/ro-crate-ruby">
49+
<meta name="keywords" content="RO-Crate">
50+
<meta charset="utf-8">
51+
</head>
52+
<body>
53+
<h1>New RO-Crate</h1>
54+
55+
<p>
56+
57+
</p>
58+
<dl>
59+
60+
61+
62+
63+
</dl>
64+
65+
<h2>Contents</h2>
66+
<ul>
67+
68+
<li>
69+
<strong><a href="http://example.com/external_ref.txt" target="_blank">http://example.com/external_ref.txt</a></strong>
70+
71+
72+
</li>
73+
74+
<li>
75+
<strong>file%20with%20spaces.txt</strong>
76+
77+
78+
</li>
79+
80+
</ul>
81+
</body>
82+
</html>

test/reader_test.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,48 @@ class ReaderTest < Test::Unit::TestCase
188188
assert crate.preview.source.source.is_a?(ROCrate::PreviewGenerator)
189189
end
190190

191+
test 'can read a 1.2 spec crate' do
192+
stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')
193+
194+
crate = ROCrate::Reader.read_directory(fixture_file('crate-spec1.2').path)
195+
file = crate.dereference('file with spaces.txt')
196+
assert file
197+
assert file.is_a?(ROCrate::File)
198+
refute file.remote?
199+
assert file.source.is_a?(ROCrate::Entry)
200+
assert_equal 'file%20with%20spaces.txt', file.id
201+
202+
ext_file = crate.dereference('http://example.com/external_ref.txt')
203+
assert ext_file
204+
assert ext_file.is_a?(ROCrate::File)
205+
assert ext_file.remote?
206+
assert ext_file.source.is_a?(ROCrate::RemoteEntry)
207+
assert_equal 'http://example.com/external_ref.txt', ext_file.id
208+
assert_equal 'file contents', ext_file.source.read
209+
assert crate.preview.source.source.is_a?(Pathname)
210+
end
211+
212+
test 'can read a 1.3 spec crate' do
213+
stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')
214+
215+
crate = ROCrate::Reader.read_directory(fixture_file('crate-spec1.3').path)
216+
file = crate.dereference('file with spaces.txt')
217+
assert file
218+
assert file.is_a?(ROCrate::File)
219+
refute file.remote?
220+
assert file.source.is_a?(ROCrate::Entry)
221+
assert_equal 'file%20with%20spaces.txt', file.id
222+
223+
ext_file = crate.dereference('http://example.com/external_ref.txt')
224+
assert ext_file
225+
assert ext_file.is_a?(ROCrate::File)
226+
assert ext_file.remote?
227+
assert ext_file.source.is_a?(ROCrate::RemoteEntry)
228+
assert_equal 'http://example.com/external_ref.txt', ext_file.id
229+
assert_equal 'file contents', ext_file.source.read
230+
assert crate.preview.source.source.is_a?(Pathname)
231+
end
232+
191233
test 'reading from directory with unlisted files' do
192234
crate = ROCrate::Reader.read_directory(fixture_file('sparse_directory_crate').path)
193235

0 commit comments

Comments
 (0)