ro-crate 0.4.9 → 0.4.10
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/Gemfile.lock +1 -1
- data/lib/ro_crate/reader.rb +22 -1
- data/ro_crate.gemspec +1 -1
- data/test/fixtures/nested_directory.zip +0 -0
- data/test/reader_test.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb6b4eba94b7190b7888cf3b1ddc8a8c6d0b464834ff48c45d9b50e6b13844ce
|
4
|
+
data.tar.gz: 70e0079caadfa3f17745e918f8109ec5908a8aa0c87d80aeaebfc55fdc03a9a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c9875be216987ceaca7e47f92112ba744109e4df9f8dcbba9023211ef3fc278f74f8ce7421523a0f443000f251627735eb01ce2357e9e526e36c23818bbba0
|
7
|
+
data.tar.gz: 0b5be2eedc7a045ccf25db4e3d800107f30d00b62e1e4b5bdb1deed1eed941897f46621bef9fa9a012891bc058857de82d6afebeb122153f8ffc944b8ca06a7a
|
data/Gemfile.lock
CHANGED
data/lib/ro_crate/reader.rb
CHANGED
@@ -84,7 +84,10 @@ module ROCrate
|
|
84
84
|
def self.read_zip(source, target_dir: Dir.mktmpdir)
|
85
85
|
unzip_to(source, target_dir)
|
86
86
|
|
87
|
-
|
87
|
+
# Traverse the unzipped directory to try and find the crate's root
|
88
|
+
root_dir = detect_root_directory(target_dir)
|
89
|
+
|
90
|
+
read_directory(root_dir)
|
88
91
|
end
|
89
92
|
|
90
93
|
##
|
@@ -252,5 +255,23 @@ module ROCrate
|
|
252
255
|
raise "Metadata entity does not reference any root entity" unless root_id
|
253
256
|
entities.delete(root_id)
|
254
257
|
end
|
258
|
+
|
259
|
+
##
|
260
|
+
# Finds an RO-Crate's root directory (where `ro-crate-metdata.json` is located) within a given directory.
|
261
|
+
#
|
262
|
+
# @param source [String, ::File, Pathname] The location of the directory.
|
263
|
+
# @return [Pathname, nil] The path to the root, or nil if not found.
|
264
|
+
def self.detect_root_directory(source)
|
265
|
+
Pathname(source).find do |entry|
|
266
|
+
if entry.file?
|
267
|
+
name = entry.basename.to_s
|
268
|
+
if name == ROCrate::Metadata::IDENTIFIER || name == ROCrate::Metadata::IDENTIFIER_1_0
|
269
|
+
return entry.parent
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
nil
|
275
|
+
end
|
255
276
|
end
|
256
277
|
end
|
data/ro_crate.gemspec
CHANGED
Binary file
|
data/test/reader_test.rb
CHANGED
@@ -215,4 +215,16 @@ class ReaderTest < Test::Unit::TestCase
|
|
215
215
|
assert string.is_a?(String)
|
216
216
|
assert_equal 11, ROCrate::Reader.read_zip(string).entries.count
|
217
217
|
end
|
218
|
+
|
219
|
+
test 'reading from zip where the crate root is nested somewhere within' do
|
220
|
+
crate = ROCrate::Reader.read_zip(fixture_file('nested_directory.zip'))
|
221
|
+
|
222
|
+
assert crate.entries['fish/info.txt']
|
223
|
+
assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
|
224
|
+
assert crate.entries['fish/root.txt']
|
225
|
+
assert crate.entries['fish/data/info.txt']
|
226
|
+
assert crate.entries['fish/data/nested.txt']
|
227
|
+
assert crate.entries['fish/data/binary.jpg']
|
228
|
+
assert_equal ['./', 'fish/', 'ro-crate-metadata.json', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
|
229
|
+
end
|
218
230
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ro-crate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Finn Bacall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- test/fixtures/directory_crate/ro-crate-preview.html
|
166
166
|
- test/fixtures/file with spaces.txt
|
167
167
|
- test/fixtures/info.txt
|
168
|
+
- test/fixtures/nested_directory.zip
|
168
169
|
- test/fixtures/spaces/file with spaces.txt
|
169
170
|
- test/fixtures/spaces/ro-crate-metadata.jsonld
|
170
171
|
- test/fixtures/sparse_directory_crate.zip
|