assembly-objectfile 1.10.1 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +10 -54
- data/lib/assembly-objectfile/content_metadata.rb +4 -1
- data/lib/assembly-objectfile/content_metadata/config.rb +2 -0
- data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +2 -0
- data/lib/assembly-objectfile/version.rb +1 -1
- data/spec/content_metadata_spec.rb +21 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 925ceb88bbc6d965b3ab9be3695e7ec318c65a11716cb5cdb2d1178af1a08174
|
4
|
+
data.tar.gz: bbc6282d8d375dd0cf49a55519563abff44429f012221dfc1b4cf0219de47aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 997b90f28dd603f11cabc20d2dc598eaf60a5f3c1b3b168b770748f6ce48377e15e8665824976a4838be52e35a54bafb508c42aca6ddaa3c6f8e31c3f627b1b2
|
7
|
+
data.tar.gz: 1033e903f01344e8944ed681e61debb128603b3b3d898269cad582d7a1a0b674fd837e4114a81033b2cbfff97da6c9d9ee17a27cfad606622eacf768436c22fc
|
data/.rubocop_todo.yml
CHANGED
@@ -1,33 +1,11 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2021-
|
3
|
+
# on 2021-03-16 21:16:42 UTC using RuboCop version 1.11.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 1
|
10
|
-
# Cop supports --auto-correct.
|
11
|
-
# Configuration parameters: EnforcedStyleAlignWith, Severity.
|
12
|
-
# SupportedStylesAlignWith: start_of_line, begin
|
13
|
-
Layout/BeginEndAlignment:
|
14
|
-
Exclude:
|
15
|
-
- 'lib/assembly-objectfile/object_fileable.rb'
|
16
|
-
|
17
|
-
# Offense count: 1
|
18
|
-
# Cop supports --auto-correct.
|
19
|
-
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
|
20
|
-
# AllowedMethods: alias_method, public, protected, private
|
21
|
-
Layout/EmptyLinesAroundAttributeAccessor:
|
22
|
-
Exclude:
|
23
|
-
- 'lib/assembly-objectfile/object_fileable.rb'
|
24
|
-
|
25
|
-
# Offense count: 1
|
26
|
-
# Cop supports --auto-correct.
|
27
|
-
Layout/RescueEnsureAlignment:
|
28
|
-
Exclude:
|
29
|
-
- 'lib/assembly-objectfile/object_fileable.rb'
|
30
|
-
|
31
9
|
# Offense count: 1
|
32
10
|
Lint/UselessAssignment:
|
33
11
|
Exclude:
|
@@ -36,23 +14,23 @@ Lint/UselessAssignment:
|
|
36
14
|
# Offense count: 3
|
37
15
|
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
38
16
|
Metrics/AbcSize:
|
39
|
-
Max:
|
17
|
+
Max: 56
|
40
18
|
|
41
19
|
# Offense count: 1
|
42
20
|
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
43
21
|
# IgnoredMethods: refine
|
44
22
|
Metrics/BlockLength:
|
45
|
-
Max:
|
23
|
+
Max: 27
|
46
24
|
|
47
25
|
# Offense count: 2
|
48
26
|
# Configuration parameters: IgnoredMethods.
|
49
27
|
Metrics/CyclomaticComplexity:
|
50
|
-
Max:
|
28
|
+
Max: 14
|
51
29
|
|
52
30
|
# Offense count: 4
|
53
31
|
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
54
32
|
Metrics/MethodLength:
|
55
|
-
Max:
|
33
|
+
Max: 31
|
56
34
|
|
57
35
|
# Offense count: 1
|
58
36
|
# Configuration parameters: CountComments, CountAsOne.
|
@@ -62,12 +40,12 @@ Metrics/ModuleLength:
|
|
62
40
|
# Offense count: 1
|
63
41
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
64
42
|
Metrics/ParameterLists:
|
65
|
-
Max:
|
43
|
+
Max: 13
|
66
44
|
|
67
45
|
# Offense count: 2
|
68
46
|
# Configuration parameters: IgnoredMethods.
|
69
47
|
Metrics/PerceivedComplexity:
|
70
|
-
Max:
|
48
|
+
Max: 15
|
71
49
|
|
72
50
|
# Offense count: 1
|
73
51
|
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
@@ -87,7 +65,7 @@ Naming/PredicateName:
|
|
87
65
|
- 'spec/**/*'
|
88
66
|
- 'lib/assembly-objectfile/object_fileable.rb'
|
89
67
|
|
90
|
-
# Offense count:
|
68
|
+
# Offense count: 9
|
91
69
|
# Configuration parameters: Max.
|
92
70
|
RSpec/ExampleLength:
|
93
71
|
Exclude:
|
@@ -107,7 +85,7 @@ RSpec/InstanceVariable:
|
|
107
85
|
Exclude:
|
108
86
|
- 'spec/object_file_spec.rb'
|
109
87
|
|
110
|
-
# Offense count:
|
88
|
+
# Offense count: 39
|
111
89
|
RSpec/MultipleExpectations:
|
112
90
|
Max: 29
|
113
91
|
|
@@ -132,29 +110,7 @@ Style/CommentedKeyword:
|
|
132
110
|
Exclude:
|
133
111
|
- 'lib/assembly-objectfile/content_metadata.rb'
|
134
112
|
|
135
|
-
# Offense count:
|
136
|
-
# Cop supports --auto-correct.
|
137
|
-
Style/KeywordParametersOrder:
|
138
|
-
Exclude:
|
139
|
-
- 'lib/assembly-objectfile/content_metadata/file.rb'
|
140
|
-
- 'lib/assembly-objectfile/content_metadata/file_set.rb'
|
141
|
-
|
142
|
-
# Offense count: 1
|
143
|
-
# Cop supports --auto-correct.
|
144
|
-
Style/RedundantAssignment:
|
145
|
-
Exclude:
|
146
|
-
- 'lib/assembly-objectfile/content_metadata.rb'
|
147
|
-
|
148
|
-
# Offense count: 5
|
149
|
-
# Cop supports --auto-correct.
|
150
|
-
Style/StringConcatenation:
|
151
|
-
Exclude:
|
152
|
-
- 'config/boot.rb'
|
153
|
-
- 'lib/assembly-objectfile.rb'
|
154
|
-
- 'lib/assembly-objectfile/object_file.rb'
|
155
|
-
- 'spec/spec_helper.rb'
|
156
|
-
|
157
|
-
# Offense count: 113
|
113
|
+
# Offense count: 116
|
158
114
|
# Cop supports --auto-correct.
|
159
115
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
160
116
|
# URISchemes: http, https
|
@@ -52,13 +52,15 @@ module Assembly
|
|
52
52
|
# :flatten_folder_structure = optional - Will remove *all* folder structure when genearting file IDs (e.g. DPG subfolders like '00','05' will be removed) when generating file IDs. This is useful if the folder structure is flattened when staging files (like for DPG).
|
53
53
|
# The default is false. If set to true, will override the "preserve_common_paths" parameter.
|
54
54
|
# :auto_labels = optional - Will add automated resource labels (e.g. "File 1") when labels are not provided by the user. The default is true.
|
55
|
+
# See https://consul.stanford.edu/pages/viewpage.action?spaceKey=chimera&title=DOR+content+types%2C+resource+types+and+interpretive+metadata for next two settings
|
56
|
+
# :reading_order = optional - only valid for simple_book, can be 'rtl' or 'ltr'. The default is 'ltr'.
|
55
57
|
# Example:
|
56
58
|
# Assembly::ContentMetadata.create_content_metadata(:druid=>'druid:nx288wh8889',:style=>:simple_image,:objects=>object_files,:add_file_attributes=>false)
|
57
59
|
def self.create_content_metadata(druid:, objects:, auto_labels: true,
|
58
60
|
add_exif: false, bundle: :default, style: :simple_image,
|
59
61
|
add_file_attributes: false, file_attributes: {},
|
60
62
|
preserve_common_paths: false, flatten_folder_structure: false,
|
61
|
-
include_root_xml: nil)
|
63
|
+
include_root_xml: nil, reading_order: 'ltr')
|
62
64
|
|
63
65
|
common_path = find_common_path(objects) unless preserve_common_paths # find common paths to all files provided if needed
|
64
66
|
|
@@ -68,6 +70,7 @@ module Assembly
|
|
68
70
|
add_file_attributes: add_file_attributes,
|
69
71
|
file_attributes: file_attributes,
|
70
72
|
add_exif: add_exif,
|
73
|
+
reading_order: reading_order,
|
71
74
|
type: object_level_type(style))
|
72
75
|
|
73
76
|
builder = NokogiriBuilder.build(druid: druid,
|
@@ -13,12 +13,14 @@ module Assembly
|
|
13
13
|
# Represents a configuration for generating the content metadata
|
14
14
|
class Config < Dry::Struct
|
15
15
|
STYLES = %w[image file book map 3d document webarchive-seed].freeze
|
16
|
+
READING_ORDERS = %w[ltr rtl].freeze
|
16
17
|
attribute :auto_labels, Types::Strict::Bool.default(true)
|
17
18
|
attribute :flatten_folder_structure, Types::Strict::Bool.default(false)
|
18
19
|
attribute :add_file_attributes, Types::Strict::Bool.default(false)
|
19
20
|
attribute :add_exif, Types::Strict::Bool.default(false)
|
20
21
|
attribute :file_attributes, Types::Strict::Hash.default({}.freeze)
|
21
22
|
attribute :type, Types::Strict::String.enum(*STYLES)
|
23
|
+
attribute :reading_order, Types::Strict::String.default('ltr').enum(*READING_ORDERS)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -15,6 +15,8 @@ module Assembly
|
|
15
15
|
|
16
16
|
Nokogiri::XML::Builder.new do |xml|
|
17
17
|
xml.contentMetadata(objectId: druid.to_s, type: config.type) do
|
18
|
+
xml.bookData(readingOrder: config.reading_order) if config.type == 'book'
|
19
|
+
|
18
20
|
filesets.each_with_index do |fileset, index| # iterate over all the resources
|
19
21
|
# start a new resource element
|
20
22
|
sequence = index + 1
|
@@ -8,7 +8,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
8
8
|
|
9
9
|
let(:xml) { Nokogiri::XML(result) }
|
10
10
|
|
11
|
-
context 'when style
|
11
|
+
context 'when style=simple_image' do
|
12
12
|
context 'when using a single tif and jp2' do
|
13
13
|
it 'generates valid content metadata with exif, adding file attributes' do
|
14
14
|
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
@@ -333,7 +333,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
333
333
|
end
|
334
334
|
end
|
335
335
|
|
336
|
-
context 'when style
|
336
|
+
context 'when style=webarchive-seed' do
|
337
337
|
context 'when using a jp2' do
|
338
338
|
it 'generates valid content metadata with exif, adding file attributes' do
|
339
339
|
objects = [Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
@@ -342,6 +342,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
342
342
|
xml = Nokogiri::XML(result)
|
343
343
|
expect(xml.errors.size).to eq 0
|
344
344
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('webarchive-seed')
|
345
|
+
expect(xml.xpath('//bookData').length).to eq 0
|
345
346
|
expect(xml.xpath('//resource').length).to eq 1
|
346
347
|
expect(xml.xpath('//resource/file').length).to eq 1
|
347
348
|
expect(xml.xpath('//resource/file/checksum').length).to eq 2
|
@@ -375,6 +376,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
375
376
|
xml = Nokogiri::XML(result)
|
376
377
|
expect(xml.errors.size).to eq 0
|
377
378
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
|
379
|
+
expect(xml.xpath('//bookData').length).to eq 0
|
378
380
|
expect(xml.xpath('//resource/file').length).to eq 2
|
379
381
|
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
380
382
|
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
|
@@ -404,6 +406,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
404
406
|
expect(xml.errors.size).to eq 0
|
405
407
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
406
408
|
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
|
409
|
+
expect(xml.xpath('//bookData')[0].attributes['readingOrder'].value).to eq('ltr')
|
407
410
|
expect(xml.xpath('//resource').length).to eq 4
|
408
411
|
expect(xml.xpath('//resource/file').length).to eq 6
|
409
412
|
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
|
@@ -428,20 +431,21 @@ RSpec.describe Assembly::ContentMetadata do
|
|
428
431
|
end
|
429
432
|
end
|
430
433
|
|
431
|
-
context "when item has a 'druid:' prefix. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg" do
|
434
|
+
context "when item has a 'druid:' prefix and specified book order. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg" do
|
432
435
|
it 'generates valid content metadata with flattening folder structure' do
|
433
436
|
objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
|
434
437
|
Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
|
435
438
|
Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
|
436
439
|
Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
|
437
440
|
test_druid = "druid:#{TEST_DRUID}"
|
438
|
-
result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true)
|
441
|
+
result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true, reading_order: 'rtl')
|
439
442
|
expect(result.class).to be String
|
440
443
|
expect(result.include?('<?xml')).to be true
|
441
444
|
xml = Nokogiri::XML(result)
|
442
445
|
expect(xml.errors.size).to eq 0
|
443
446
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
444
447
|
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
|
448
|
+
expect(xml.xpath('//bookData')[0].attributes['readingOrder'].value).to eq('rtl')
|
445
449
|
expect(test_druid).to eq("druid:#{TEST_DRUID}")
|
446
450
|
expect(xml.xpath('//resource').length).to eq 3
|
447
451
|
expect(xml.xpath('//resource/file').length).to be 7
|
@@ -466,6 +470,14 @@ RSpec.describe Assembly::ContentMetadata do
|
|
466
470
|
end
|
467
471
|
end
|
468
472
|
|
473
|
+
context 'throws an error with invalid reading order' do
|
474
|
+
subject(:result) { described_class.create_content_metadata(druid: "druid:#{TEST_DRUID}", bundle: :dpg, objects: [], style: :simple_book, flatten_folder_structure: true, reading_order: 'bogus') }
|
475
|
+
|
476
|
+
it 'generates valid content metadata with flattening folder structure' do
|
477
|
+
expect { result }.to raise_error(Dry::Struct::Error)
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
469
481
|
context 'when using two tifs' do
|
470
482
|
it 'generates valid content metadata for two tifs of style=simple_book' do
|
471
483
|
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
|
@@ -493,7 +505,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
493
505
|
end
|
494
506
|
end
|
495
507
|
|
496
|
-
context 'when
|
508
|
+
context 'when style=book_with_pdf' do
|
497
509
|
context 'when using two tiffs and a pdf' do
|
498
510
|
let(:objects) do
|
499
511
|
[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
|
@@ -580,6 +592,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
580
592
|
xml = Nokogiri::XML(result)
|
581
593
|
expect(xml.errors.size).to eq 0
|
582
594
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
|
595
|
+
expect(xml.xpath('//bookData').length).to eq 0
|
583
596
|
expect(xml.xpath('//resource').length).to eq 4
|
584
597
|
expect(xml.xpath('//resource/file').length).to eq 4
|
585
598
|
expect(xml.xpath('//label').length).to eq 4
|
@@ -611,6 +624,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
611
624
|
it 'generates valid content metadata for two tifs' do
|
612
625
|
expect(xml.errors.size).to eq 0
|
613
626
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
627
|
+
expect(xml.xpath('//bookData').length).to eq 1
|
614
628
|
expect(xml.xpath('//resource').length).to eq 2
|
615
629
|
expect(xml.xpath('//resource/file').length).to eq 2
|
616
630
|
expect(xml.xpath('//label').length).to eq 2
|
@@ -641,6 +655,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
641
655
|
it 'generates valid content metadata' do
|
642
656
|
expect(xml.errors.size).to eq 0
|
643
657
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('document')
|
658
|
+
expect(xml.xpath('//bookData').length).to eq 0
|
644
659
|
expect(xml.xpath('//resource').length).to eq 1
|
645
660
|
expect(xml.xpath('//resource/file').length).to eq 1
|
646
661
|
expect(xml.xpath('//label').length).to eq 1
|
@@ -713,6 +728,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
713
728
|
it 'generates valid content metadata' do
|
714
729
|
expect(xml.errors.size).to eq 0
|
715
730
|
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
|
731
|
+
expect(xml.xpath('//bookData').length).to eq 0
|
716
732
|
expect(xml.xpath('//resource').length).to eq 4
|
717
733
|
expect(xml.xpath('//resource/file').length).to eq 4
|
718
734
|
expect(xml.xpath('//label').length).to eq 4
|