ro-crate 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c4aabc50994541bbcbb2071b805f457e47c9e30176299fdde40741aa5ff1094
4
- data.tar.gz: 0f4d7df6b4eb21961446ce2e3c05fe337fa7ed9e161eb21a7651b8ea6292f988
3
+ metadata.gz: 125d04bfd22ce828caf9adb16e0dd4d5fcd70a67df4389e3d5444e23b8a69513
4
+ data.tar.gz: be9cfce536b620833ba46a9595ae8bdca8d9ec5aab459827119f2f88e7cd3565
5
5
  SHA512:
6
- metadata.gz: f590b0e08e5f813474e4c46e3230b01999d17cf349645b8c86285c8dbe3cd371563405e1e1143a7b68d115764373847ace352029beed404a5cc069e64ef40dab
7
- data.tar.gz: 972a1e14b6faa4986bad9138fdd39861bf54af81dd5678354f84cc0f4bbc3b50252e38cf948d013bb6a979365dedc74e81c48661115f0cd3f408fcdd0744f777
6
+ metadata.gz: 3a44da2d8253ee5758cdaf9d87c152e1f8d263109004baec0983f9d348bde955c0bf9ba49ff6afa356d007a3e2b9e34ed3ca6b174764720c32e4400bf3cdf5ec
7
+ data.tar.gz: d72d085135c8b6e39dd2389e79db97b645813dde486220fb79076841a8a5499ce182bd3a8e79a423602e943526bc4e718e58de674de10875f43fdda3af3e8a07
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  ![Tests](https://github.com/ResearchObject/ro-crate-ruby/actions/workflows/tests.yml/badge.svg)
4
4
 
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.
6
6
 
7
7
  * 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/
9
9
 
10
10
  ## Installation
11
11
 
@@ -6,8 +6,8 @@ module ROCrate
6
6
  IDENTIFIER_1_0 = 'ro-crate-metadata.jsonld'.freeze # 1.0 spec identifier
7
7
  RO_CRATE_BASE = 'https://w3id.org/ro/crate/'
8
8
 
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
11
11
 
12
12
  CONTEXT = "#{RO_CRATE_BASE}#{DEFAULT_VERSION}/context".freeze
13
13
  SPEC = "#{RO_CRATE_BASE}#{DEFAULT_VERSION}".freeze
@@ -233,13 +233,25 @@ module ROCrate
233
233
 
234
234
  entity_hash.each do |id, entity_props|
235
235
  entity_class = ROCrate::ContextualEntity.specialize(entity_props)
236
- entity = entity_class.new(crate, id, entity_props)
236
+ entity = entity_class.new(crate, decode_local_id(id), entity_props)
237
237
  entities << entity
238
238
  end
239
239
 
240
240
  entities
241
241
  end
242
242
 
243
+ ##
244
+ # Decode a local (non-absolute) ID read from the metadata, so that it is not encoded a second time when it is
245
+ # formatted on assignment to an entity. Absolute IDs are returned unchanged.
246
+ # @param id [String] The ID as it appears in the metadata.
247
+ # @return [String] The decoded ID.
248
+ def self.decode_local_id(id)
249
+ uri = URI(id) rescue nil
250
+ return id if uri&.absolute?
251
+
252
+ Addressable::URI.unencode_component(id)
253
+ end
254
+
243
255
  ##
244
256
  # Create a DataEntity of the given class.
245
257
  # @param crate [Crate] The RO-Crate being read.
@@ -250,7 +262,7 @@ module ROCrate
250
262
  def self.create_data_entity(crate, entity_class, source, entity_props)
251
263
  id = entity_props.delete('@id')
252
264
  raise ROCrate::ReadException, "Data Entity missing '@id': #{entity_props.inspect}" unless id
253
- decoded_id = URI.decode_www_form_component(id)
265
+ decoded_id = decode_local_id(id)
254
266
  path = nil
255
267
  uri = URI(id) rescue nil
256
268
  if uri&.absolute?
data/ro_crate.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ro-crate'
3
- s.version = '0.6.0'
3
+ s.version = '0.7.1'
4
4
  s.summary = 'Create, manipulate, read RO-Crates.'
5
5
  s.authors = ['Finn Bacall']
6
6
  s.email = 'finn.bacall@manchester.ac.uk'
data/test/crate_test.rb CHANGED
@@ -378,12 +378,12 @@ class CrateTest < Test::Unit::TestCase
378
378
  assert crate.get('#joehouse')
379
379
  end
380
380
 
381
- test 'defaults to RO-Crate spec 1.2' do
381
+ test 'defaults to RO-Crate spec 1.3' do
382
382
  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'])
387
387
  end
388
388
 
389
389
  test 'can write older spec version' do
@@ -0,0 +1 @@
1
+ I have spaces in my name
@@ -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
+ }
@@ -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>
@@ -0,0 +1 @@
1
+ I have spaces in my name
@@ -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
+ }
@@ -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>
data/test/reader_test.rb CHANGED
@@ -167,6 +167,49 @@ class ReaderTest < Test::Unit::TestCase
167
167
  end
168
168
  end
169
169
 
170
+ test 'reading does not double-encode encoded contextual entity IDs' do
171
+ crate = ROCrate::Crate.new
172
+ jane = crate.add_person('Jane Bloggs', name: 'Jane Bloggs')
173
+ team = crate.add_contextual_entity(ROCrate::ContextualEntity.new(crate, 'C++ Team', name: 'C++ Team'))
174
+ crate.author = [jane, team]
175
+ assert_equal '#Jane%20Bloggs', jane.id
176
+ assert_equal '#C++%20Team', team.id
177
+
178
+ # Write/Read the crate 3 times to ensure!
179
+ 3.times do
180
+ Tempfile.create do |file|
181
+ ROCrate::Writer.new(crate).write_zip(file)
182
+ crate = ROCrate::Reader.read_zip(file)
183
+ end
184
+ end
185
+
186
+ ids = crate.contextual_entities.map(&:id)
187
+ assert_includes ids, '#Jane%20Bloggs'
188
+ assert_includes ids, '#C++%20Team'
189
+ assert_equal ['#Jane%20Bloggs', '#C++%20Team'], crate['author'].map { |ref| ref['@id'] }
190
+ assert_equal ['Jane Bloggs', 'C++ Team'], crate.author.map { |a| a['name'] }
191
+ end
192
+
193
+ test 'reading preserves plus signs in data entity IDs' do
194
+ crate = ROCrate::Crate.new
195
+ file = crate.add_file(StringIO.new('notes'), 'C++ notes.txt')
196
+ assert_equal 'C++%20notes.txt', file.id
197
+
198
+ # Write/Read the crate 3 times to ensure!
199
+ 3.times do
200
+ Tempfile.create do |f|
201
+ ROCrate::Writer.new(crate).write_zip(f)
202
+ crate = ROCrate::Reader.read_zip(f)
203
+ end
204
+ end
205
+
206
+ file = crate.dereference('C++%20notes.txt')
207
+ assert file
208
+ assert_equal 'C++%20notes.txt', file.id
209
+ assert_equal ['C++%20notes.txt'], crate['hasPart'].map { |ref| ref['@id'] }
210
+ assert_equal 'notes', file.source.read
211
+ end
212
+
170
213
  test 'can read a 1.1 spec crate' do
171
214
  stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')
172
215
 
@@ -188,6 +231,48 @@ class ReaderTest < Test::Unit::TestCase
188
231
  assert crate.preview.source.source.is_a?(ROCrate::PreviewGenerator)
189
232
  end
190
233
 
234
+ test 'can read a 1.2 spec crate' do
235
+ stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')
236
+
237
+ crate = ROCrate::Reader.read_directory(fixture_file('crate-spec1.2').path)
238
+ file = crate.dereference('file with spaces.txt')
239
+ assert file
240
+ assert file.is_a?(ROCrate::File)
241
+ refute file.remote?
242
+ assert file.source.is_a?(ROCrate::Entry)
243
+ assert_equal 'file%20with%20spaces.txt', file.id
244
+
245
+ ext_file = crate.dereference('http://example.com/external_ref.txt')
246
+ assert ext_file
247
+ assert ext_file.is_a?(ROCrate::File)
248
+ assert ext_file.remote?
249
+ assert ext_file.source.is_a?(ROCrate::RemoteEntry)
250
+ assert_equal 'http://example.com/external_ref.txt', ext_file.id
251
+ assert_equal 'file contents', ext_file.source.read
252
+ assert crate.preview.source.source.is_a?(Pathname)
253
+ end
254
+
255
+ test 'can read a 1.3 spec crate' do
256
+ stub_request(:get, "http://example.com/external_ref.txt").to_return(status: 200, body: 'file contents')
257
+
258
+ crate = ROCrate::Reader.read_directory(fixture_file('crate-spec1.3').path)
259
+ file = crate.dereference('file with spaces.txt')
260
+ assert file
261
+ assert file.is_a?(ROCrate::File)
262
+ refute file.remote?
263
+ assert file.source.is_a?(ROCrate::Entry)
264
+ assert_equal 'file%20with%20spaces.txt', file.id
265
+
266
+ ext_file = crate.dereference('http://example.com/external_ref.txt')
267
+ assert ext_file
268
+ assert ext_file.is_a?(ROCrate::File)
269
+ assert ext_file.remote?
270
+ assert ext_file.source.is_a?(ROCrate::RemoteEntry)
271
+ assert_equal 'http://example.com/external_ref.txt', ext_file.id
272
+ assert_equal 'file contents', ext_file.source.read
273
+ assert crate.preview.source.source.is_a?(Pathname)
274
+ end
275
+
191
276
  test 'reading from directory with unlisted files' do
192
277
  crate = ROCrate::Reader.read_directory(fixture_file('sparse_directory_crate').path)
193
278
 
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ro-crate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn Bacall
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: addressable
@@ -133,6 +134,7 @@ dependencies:
133
134
  - - "~>"
134
135
  - !ruby/object:Gem::Version
135
136
  version: 3.4.4
137
+ description:
136
138
  email: finn.bacall@manchester.ac.uk
137
139
  executables: []
138
140
  extensions: []
@@ -185,6 +187,12 @@ files:
185
187
  - test/fixtures/conflicting_data_directory/nested.txt
186
188
  - test/fixtures/crate-spec1.1/file with spaces.txt
187
189
  - test/fixtures/crate-spec1.1/ro-crate-metadata.json
190
+ - test/fixtures/crate-spec1.2/file with spaces.txt
191
+ - test/fixtures/crate-spec1.2/ro-crate-metadata.json
192
+ - test/fixtures/crate-spec1.2/ro-crate-preview.html
193
+ - test/fixtures/crate-spec1.3/file with spaces.txt
194
+ - test/fixtures/crate-spec1.3/ro-crate-metadata.json
195
+ - test/fixtures/crate-spec1.3/ro-crate-preview.html
188
196
  - test/fixtures/data.csv
189
197
  - test/fixtures/dir_symlink
190
198
  - test/fixtures/directory.zip
@@ -2480,6 +2488,7 @@ homepage: https://github.com/ResearchObject/ro-crate-ruby
2480
2488
  licenses:
2481
2489
  - MIT
2482
2490
  metadata: {}
2491
+ post_install_message:
2483
2492
  rdoc_options: []
2484
2493
  require_paths:
2485
2494
  - lib
@@ -2494,7 +2503,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2494
2503
  - !ruby/object:Gem::Version
2495
2504
  version: '0'
2496
2505
  requirements: []
2497
- rubygems_version: 3.6.9
2506
+ rubygems_version: 3.5.22
2507
+ signing_key:
2498
2508
  specification_version: 4
2499
2509
  summary: Create, manipulate, read RO-Crates.
2500
2510
  test_files: []