ro-crate 0.7.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 +4 -4
- data/lib/ro_crate/reader.rb +14 -2
- data/ro_crate.gemspec +1 -1
- data/test/reader_test.rb +43 -0
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 125d04bfd22ce828caf9adb16e0dd4d5fcd70a67df4389e3d5444e23b8a69513
|
|
4
|
+
data.tar.gz: be9cfce536b620833ba46a9595ae8bdca8d9ec5aab459827119f2f88e7cd3565
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3a44da2d8253ee5758cdaf9d87c152e1f8d263109004baec0983f9d348bde955c0bf9ba49ff6afa356d007a3e2b9e34ed3ca6b174764720c32e4400bf3cdf5ec
|
|
7
|
+
data.tar.gz: d72d085135c8b6e39dd2389e79db97b645813dde486220fb79076841a8a5499ce182bd3a8e79a423602e943526bc4e718e58de674de10875f43fdda3af3e8a07
|
data/lib/ro_crate/reader.rb
CHANGED
|
@@ -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 =
|
|
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
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
|
|
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.7.
|
|
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:
|
|
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: []
|
|
@@ -2486,6 +2488,7 @@ homepage: https://github.com/ResearchObject/ro-crate-ruby
|
|
|
2486
2488
|
licenses:
|
|
2487
2489
|
- MIT
|
|
2488
2490
|
metadata: {}
|
|
2491
|
+
post_install_message:
|
|
2489
2492
|
rdoc_options: []
|
|
2490
2493
|
require_paths:
|
|
2491
2494
|
- lib
|
|
@@ -2500,7 +2503,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
2500
2503
|
- !ruby/object:Gem::Version
|
|
2501
2504
|
version: '0'
|
|
2502
2505
|
requirements: []
|
|
2503
|
-
rubygems_version: 3.
|
|
2506
|
+
rubygems_version: 3.5.22
|
|
2507
|
+
signing_key:
|
|
2504
2508
|
specification_version: 4
|
|
2505
2509
|
summary: Create, manipulate, read RO-Crates.
|
|
2506
2510
|
test_files: []
|