assembly-objectfile 1.11.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -0
  3. data/.github/pull_request_template.md +3 -5
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +87 -15
  6. data/.rubocop_todo.yml +19 -74
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +106 -0
  9. data/README.md +1 -1
  10. data/assembly-objectfile.gemspec +5 -6
  11. data/lib/assembly-objectfile/object_file.rb +253 -3
  12. data/lib/assembly-objectfile/version.rb +2 -2
  13. data/lib/assembly-objectfile.rb +0 -5
  14. data/spec/object_file_spec.rb +411 -167
  15. data/spec/spec_helper.rb +3 -31
  16. data/spec/test_data/empty.txt +0 -0
  17. metadata +35 -121
  18. data/.travis.yml +0 -20
  19. data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
  20. data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
  21. data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
  22. data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
  23. data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
  24. data/lib/assembly-objectfile/content_metadata.rb +0 -117
  25. data/lib/assembly-objectfile/object_fileable.rb +0 -278
  26. data/spec/content_metadata_spec.rb +0 -791
  27. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  28. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  29. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  30. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  31. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  32. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  33. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  34. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  35. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  36. data/spec/test_data/input/res1_image1.jp2 +0 -0
  37. data/spec/test_data/input/res1_image2.jp2 +0 -0
  38. data/spec/test_data/input/res1_image2.tif +0 -0
  39. data/spec/test_data/input/res1_teifile.txt +0 -1
  40. data/spec/test_data/input/res2_image1.jp2 +0 -0
  41. data/spec/test_data/input/res2_image1.tif +0 -0
  42. data/spec/test_data/input/res2_image2.jp2 +0 -0
  43. data/spec/test_data/input/res2_image2.tif +0 -0
  44. data/spec/test_data/input/res2_teifile.txt +0 -1
  45. data/spec/test_data/input/res2_textfile.txt +0 -1
  46. data/spec/test_data/input/res3_image1.jp2 +0 -0
  47. data/spec/test_data/input/res3_image1.tif +0 -0
  48. data/spec/test_data/input/res3_teifile.txt +0 -1
  49. data/spec/test_data/input/test.pdf +0 -1
  50. data/spec/test_data/input/test2.jp2 +0 -0
  51. data/spec/test_data/input/test2.tif +0 -0
data/spec/spec_helper.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
- bootfile = File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
7
- require bootfile
6
+ require File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
7
+ require 'pry-byebug'
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.order = 'random'
@@ -14,44 +14,16 @@ TEST_DATA_DIR = File.join(Assembly::PATH_TO_GEM, 'spec', 'test_data')
14
14
  TEST_INPUT_DIR = File.join(TEST_DATA_DIR, 'input')
15
15
  TEST_OUTPUT_DIR = File.join(TEST_DATA_DIR, 'output')
16
16
  TEST_TIF_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.tif')
17
- TEST_TIF_INPUT_FILE2 = File.join(TEST_INPUT_DIR, 'test2.tif')
18
- TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
17
+ TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
19
18
  TEST_JP2_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jp2')
20
- TEST_JP2_INPUT_FILE2 = File.join(TEST_INPUT_DIR, 'test2.jp2')
21
19
  TEST_JP2_OUTPUT_FILE = File.join(TEST_OUTPUT_DIR, 'test.jp2')
22
- TEST_PDF_FILE = File.join(TEST_INPUT_DIR, 'test.pdf')
23
-
24
- TEST_DPG_TIF = File.join(TEST_INPUT_DIR, 'oo000oo0001', '00', 'oo000oo0001_00_001.tif')
25
- TEST_DPG_TIF2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '00', 'oo000oo0001_00_002.tif')
26
- TEST_DPG_JP = File.join(TEST_INPUT_DIR, 'oo000oo0001', '05', 'oo000oo0001_05_001.jp2')
27
- TEST_DPG_JP2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '05', 'oo000oo0001_05_002.jp2')
28
- TEST_DPG_PDF = File.join(TEST_INPUT_DIR, 'oo000oo0001', '15', 'oo000oo0001_15_001.pdf')
29
- TEST_DPG_PDF2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '15', 'oo000oo0001_15_002.pdf')
30
- TEST_DPG_SPECIAL_PDF1 = File.join(TEST_INPUT_DIR, 'oo000oo0001', 'oo000oo0001_book.pdf')
31
- TEST_DPG_SPECIAL_PDF2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '31', 'oo000oo0001_31_001.pdf')
32
- TEST_DPG_SPECIAL_TIF = File.join(TEST_INPUT_DIR, 'oo000oo0001', '50', 'oo000oo0001_50_001.tif')
33
20
 
34
21
  TEST_TIFF_NO_COLOR_FILE = File.join(TEST_INPUT_DIR, 'test_no_color_profile.tif')
35
22
 
36
23
  TEST_RES1_TIF1 = File.join(TEST_INPUT_DIR, 'res1_image1.tif')
37
- TEST_RES1_JP1 = File.join(TEST_INPUT_DIR, 'res1_image1.jp2')
38
- TEST_RES1_TIF2 = File.join(TEST_INPUT_DIR, 'res1_image2.tif')
39
- TEST_RES1_JP2 = File.join(TEST_INPUT_DIR, 'res1_image2.jp2')
40
- TEST_RES1_TEI = File.join(TEST_INPUT_DIR, 'res1_teifile.txt')
41
24
  TEST_RES1_TEXT = File.join(TEST_INPUT_DIR, 'res1_textfile.txt')
42
25
  TEST_RES1_PDF = File.join(TEST_INPUT_DIR, 'res1_transcript.pdf')
43
26
 
44
- TEST_RES2_TIF1 = File.join(TEST_INPUT_DIR, 'res2_image1.tif')
45
- TEST_RES2_JP1 = File.join(TEST_INPUT_DIR, 'res2_image1.jp2')
46
- TEST_RES2_TIF2 = File.join(TEST_INPUT_DIR, 'res2_image2.tif')
47
- TEST_RES2_JP2 = File.join(TEST_INPUT_DIR, 'res2_image2.jp2')
48
- TEST_RES2_TEI = File.join(TEST_INPUT_DIR, 'res2_teifile.txt')
49
- TEST_RES2_TEXT = File.join(TEST_INPUT_DIR, 'res2_textfile.txt')
50
-
51
- TEST_RES3_TIF1 = File.join(TEST_INPUT_DIR, 'res3_image1.tif')
52
- TEST_RES3_JP1 = File.join(TEST_INPUT_DIR, 'res3_image1.jp2')
53
- TEST_RES3_TEI = File.join(TEST_INPUT_DIR, 'res3_teifile.txt')
54
-
55
27
  TEST_FILE_NO_EXIF = File.join(TEST_INPUT_DIR, 'file_with_no_exif.xml')
56
28
 
57
29
  TEST_JSON_FILE = File.join(TEST_INPUT_DIR, 'test.json')
File without changes
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assembly-objectfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
8
8
  - Renzo Sanchez-Silva
9
9
  - Monty Hindman
10
10
  - Tony Calavano
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2022-01-05 00:00:00.000000000 Z
14
+ date: 2022-07-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -41,34 +41,6 @@ dependencies:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
- - !ruby/object:Gem::Dependency
45
- name: dry-struct
46
- requirement: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - "~>"
49
- - !ruby/object:Gem::Version
50
- version: '1.0'
51
- type: :runtime
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '1.0'
58
- - !ruby/object:Gem::Dependency
59
- name: dry-types
60
- requirement: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - "~>"
63
- - !ruby/object:Gem::Version
64
- version: '1.1'
65
- type: :runtime
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '1.1'
72
44
  - !ruby/object:Gem::Dependency
73
45
  name: mime-types
74
46
  requirement: !ruby/object:Gem::Requirement
@@ -125,6 +97,20 @@ dependencies:
125
97
  - - ">="
126
98
  - !ruby/object:Gem::Version
127
99
  version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: pry-byebug
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
128
114
  - !ruby/object:Gem::Dependency
129
115
  name: rake
130
116
  requirement: !ruby/object:Gem::Requirement
@@ -157,16 +143,16 @@ dependencies:
157
143
  name: rubocop
158
144
  requirement: !ruby/object:Gem::Requirement
159
145
  requirements:
160
- - - ">="
146
+ - - "~>"
161
147
  - !ruby/object:Gem::Version
162
- version: '0'
148
+ version: '1.25'
163
149
  type: :development
164
150
  prerelease: false
165
151
  version_requirements: !ruby/object:Gem::Requirement
166
152
  requirements:
167
- - - ">="
153
+ - - "~>"
168
154
  - !ruby/object:Gem::Version
169
- version: '0'
155
+ version: '1.25'
170
156
  - !ruby/object:Gem::Dependency
171
157
  name: rubocop-rspec
172
158
  requirement: !ruby/object:Gem::Requirement
@@ -185,16 +171,16 @@ dependencies:
185
171
  name: simplecov
186
172
  requirement: !ruby/object:Gem::Requirement
187
173
  requirements:
188
- - - "~>"
174
+ - - ">="
189
175
  - !ruby/object:Gem::Version
190
- version: 0.17.0
176
+ version: '0'
191
177
  type: :development
192
178
  prerelease: false
193
179
  version_requirements: !ruby/object:Gem::Requirement
194
180
  requirements:
195
- - - "~>"
181
+ - - ">="
196
182
  - !ruby/object:Gem::Version
197
- version: 0.17.0
183
+ version: '0'
198
184
  description: Get exif data, file sizes and more.
199
185
  email:
200
186
  - pmangiafico@stanford.edu
@@ -202,14 +188,15 @@ executables: []
202
188
  extensions: []
203
189
  extra_rdoc_files: []
204
190
  files:
191
+ - ".circleci/config.yml"
205
192
  - ".github/ISSUE_TEMPLATE/bug_report.md"
206
193
  - ".github/pull_request_template.md"
207
194
  - ".gitignore"
208
195
  - ".rubocop.yml"
209
196
  - ".rubocop_todo.yml"
210
197
  - ".rvmrc.example"
211
- - ".travis.yml"
212
198
  - Gemfile
199
+ - Gemfile.lock
213
200
  - LICENSE
214
201
  - README.md
215
202
  - Rakefile
@@ -218,62 +205,31 @@ files:
218
205
  - bin/run_all_tests
219
206
  - config/boot.rb
220
207
  - lib/assembly-objectfile.rb
221
- - lib/assembly-objectfile/content_metadata.rb
222
- - lib/assembly-objectfile/content_metadata/config.rb
223
- - lib/assembly-objectfile/content_metadata/file.rb
224
- - lib/assembly-objectfile/content_metadata/file_set.rb
225
- - lib/assembly-objectfile/content_metadata/file_set_builder.rb
226
- - lib/assembly-objectfile/content_metadata/nokogiri_builder.rb
227
208
  - lib/assembly-objectfile/object_file.rb
228
- - lib/assembly-objectfile/object_fileable.rb
229
209
  - lib/assembly-objectfile/version.rb
230
210
  - profiles/AdobeRGB1998.icc
231
211
  - profiles/DotGain20.icc
232
212
  - profiles/sRGBIEC6196621.icc
233
- - spec/content_metadata_spec.rb
234
213
  - spec/object_file_spec.rb
235
214
  - spec/spec_helper.rb
215
+ - spec/test_data/empty.txt
236
216
  - spec/test_data/input/.empty
237
217
  - spec/test_data/input/file_with_no_exif.xml
238
- - spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif
239
- - spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif
240
- - spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2
241
- - spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2
242
- - spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf
243
- - spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf
244
- - spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf
245
- - spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif
246
- - spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf
247
- - spec/test_data/input/res1_image1.jp2
248
218
  - spec/test_data/input/res1_image1.tif
249
- - spec/test_data/input/res1_image2.jp2
250
- - spec/test_data/input/res1_image2.tif
251
- - spec/test_data/input/res1_teifile.txt
252
219
  - spec/test_data/input/res1_textfile.txt
253
220
  - spec/test_data/input/res1_transcript.pdf
254
- - spec/test_data/input/res2_image1.jp2
255
- - spec/test_data/input/res2_image1.tif
256
- - spec/test_data/input/res2_image2.jp2
257
- - spec/test_data/input/res2_image2.tif
258
- - spec/test_data/input/res2_teifile.txt
259
- - spec/test_data/input/res2_textfile.txt
260
- - spec/test_data/input/res3_image1.jp2
261
- - spec/test_data/input/res3_image1.tif
262
- - spec/test_data/input/res3_teifile.txt
263
221
  - spec/test_data/input/someobject.obj
264
222
  - spec/test_data/input/someobject.ply
265
223
  - spec/test_data/input/test.jp2
266
224
  - spec/test_data/input/test.json
267
- - spec/test_data/input/test.pdf
268
225
  - spec/test_data/input/test.tif
269
- - spec/test_data/input/test2.jp2
270
- - spec/test_data/input/test2.tif
271
226
  - spec/test_data/input/test_no_color_profile.tif
272
227
  homepage: https://github.com/sul-dlss/assembly-objectfile
273
228
  licenses:
274
229
  - ALv2
275
- metadata: {}
276
- post_install_message:
230
+ metadata:
231
+ rubygems_mfa_required: 'true'
232
+ post_install_message:
277
233
  rdoc_options: []
278
234
  require_paths:
279
235
  - lib
@@ -281,58 +237,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
281
237
  requirements:
282
238
  - - ">="
283
239
  - !ruby/object:Gem::Version
284
- version: '2.5'
285
- - - "<"
286
- - !ruby/object:Gem::Version
287
- version: '4'
240
+ version: '3.0'
288
241
  required_rubygems_version: !ruby/object:Gem::Requirement
289
242
  requirements:
290
243
  - - ">="
291
244
  - !ruby/object:Gem::Version
292
245
  version: '0'
293
246
  requirements: []
294
- rubygems_version: 3.1.4
295
- signing_key:
247
+ rubygems_version: 3.3.7
248
+ signing_key:
296
249
  specification_version: 4
297
250
  summary: Ruby immplementation of file services needed to prepare objects to be accessioned
298
251
  in SULAIR digital library
299
- test_files:
300
- - spec/content_metadata_spec.rb
301
- - spec/object_file_spec.rb
302
- - spec/spec_helper.rb
303
- - spec/test_data/input/.empty
304
- - spec/test_data/input/file_with_no_exif.xml
305
- - spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif
306
- - spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif
307
- - spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2
308
- - spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2
309
- - spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf
310
- - spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf
311
- - spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf
312
- - spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif
313
- - spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf
314
- - spec/test_data/input/res1_image1.jp2
315
- - spec/test_data/input/res1_image1.tif
316
- - spec/test_data/input/res1_image2.jp2
317
- - spec/test_data/input/res1_image2.tif
318
- - spec/test_data/input/res1_teifile.txt
319
- - spec/test_data/input/res1_textfile.txt
320
- - spec/test_data/input/res1_transcript.pdf
321
- - spec/test_data/input/res2_image1.jp2
322
- - spec/test_data/input/res2_image1.tif
323
- - spec/test_data/input/res2_image2.jp2
324
- - spec/test_data/input/res2_image2.tif
325
- - spec/test_data/input/res2_teifile.txt
326
- - spec/test_data/input/res2_textfile.txt
327
- - spec/test_data/input/res3_image1.jp2
328
- - spec/test_data/input/res3_image1.tif
329
- - spec/test_data/input/res3_teifile.txt
330
- - spec/test_data/input/someobject.obj
331
- - spec/test_data/input/someobject.ply
332
- - spec/test_data/input/test.jp2
333
- - spec/test_data/input/test.json
334
- - spec/test_data/input/test.pdf
335
- - spec/test_data/input/test.tif
336
- - spec/test_data/input/test2.jp2
337
- - spec/test_data/input/test2.tif
338
- - spec/test_data/input/test_no_color_profile.tif
252
+ test_files: []
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5.7
4
- - 2.6.5
5
- addons:
6
- apt:
7
- packages:
8
- - libimage-exiftool-perl
9
- before_script:
10
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
- - chmod +x ./cc-test-reporter
12
- - ./cc-test-reporter before-build
13
- script:
14
- - bundle exec rubocop
15
- - bundle exec rake
16
- after_script:
17
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
18
-
19
- notifications:
20
- email: false
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry-struct'
4
- require 'dry-types'
5
-
6
- module Assembly
7
- class ContentMetadata
8
- # Types for the configuration
9
- module Types
10
- include Dry.Types()
11
- end
12
-
13
- # Represents a configuration for generating the content metadata
14
- class Config < Dry::Struct
15
- STYLES = %w[image file book map 3d document webarchive-seed].freeze
16
- READING_ORDERS = %w[ltr rtl].freeze
17
- attribute :auto_labels, Types::Strict::Bool.default(true)
18
- attribute :flatten_folder_structure, Types::Strict::Bool.default(false)
19
- attribute :add_file_attributes, Types::Strict::Bool.default(false)
20
- attribute :add_exif, Types::Strict::Bool.default(false)
21
- attribute :file_attributes, Types::Strict::Hash.default({}.freeze)
22
- attribute :type, Types::Strict::String.enum(*STYLES)
23
- attribute :reading_order, Types::Strict::String.default('ltr').enum(*READING_ORDERS)
24
- end
25
- end
26
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/module/delegation'
4
-
5
- module Assembly
6
- class ContentMetadata
7
- # Represents a single File
8
- class File
9
- # default publish/preserve/shelve attributes used in content metadata
10
- # if no mimetype specific attributes are specified for a given file, define some defaults, and override for specific mimetypes below
11
- ATTRIBUTES_FOR_TYPE = {
12
- 'default' => { preserve: 'yes', shelve: 'no', publish: 'no' },
13
- 'image/tif' => { preserve: 'yes', shelve: 'no', publish: 'no' },
14
- 'image/tiff' => { preserve: 'yes', shelve: 'no', publish: 'no' },
15
- 'image/jp2' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
16
- 'image/jpeg' => { preserve: 'yes', shelve: 'no', publish: 'no' },
17
- 'audio/wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
18
- 'audio/x-wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
19
- 'audio/mp3' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
20
- 'audio/mpeg' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
21
- 'application/pdf' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
22
- 'plain/text' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
23
- 'text/plain' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
24
- 'image/png' => { preserve: 'yes', shelve: 'yes', publish: 'no' },
25
- 'application/zip' => { preserve: 'yes', shelve: 'no', publish: 'no' },
26
- 'application/json' => { preserve: 'yes', shelve: 'yes', publish: 'yes' }
27
- }.freeze
28
-
29
- # @param [Symbol] bundle
30
- # @param [Assembly::ObjectFile] file
31
- # @param style
32
- def initialize(file:, bundle: nil, style: nil)
33
- @bundle = bundle
34
- @file = file
35
- @style = style
36
- end
37
-
38
- delegate :sha1, :md5, :provider_md5, :provider_sha1, :mimetype, :filesize, :image?, to: :file
39
-
40
- def file_id(common_path:, flatten_folder_structure:)
41
- # set file id attribute, first check the relative_path parameter on the object, and if it is set, just use that
42
- return file.relative_path if file.relative_path
43
-
44
- # if the relative_path attribute is not set, then use the path attribute and check to see if we need to remove the common part of the path
45
- file_id = common_path ? file.path.gsub(common_path, '') : file.path
46
- file_id = ::File.basename(file_id) if flatten_folder_structure
47
- file_id
48
- end
49
-
50
- def file_attributes(provided_file_attributes)
51
- file.file_attributes || provided_file_attributes[mimetype] || provided_file_attributes['default'] || ATTRIBUTES_FOR_TYPE[mimetype] || ATTRIBUTES_FOR_TYPE['default']
52
- end
53
-
54
- def image_data
55
- { height: file.exif.imageheight, width: file.exif.imagewidth }
56
- end
57
-
58
- private
59
-
60
- attr_reader :file
61
- end
62
- end
63
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/object/blank'
4
-
5
- module Assembly
6
- class ContentMetadata
7
- # Represents a groups of related Files, such as a single master file and the derivatives
8
- class FileSet
9
- # @param [Boolean] dpg (false) is it a dpg bundle?
10
- # @param [Array<Assembly::ObjectFile>] resource_files
11
- # @param style
12
- def initialize(resource_files:, style:, dpg: false)
13
- @dpg = dpg
14
- @resource_files = resource_files
15
- @style = style
16
- end
17
-
18
- # objects in the special DPG folders are always type=object when we using :bundle=>:dpg
19
- # otherwise look at the style to determine the resource_type_description
20
- def resource_type_description
21
- @resource_type_description ||= special_dpg_resource? ? 'object' : resource_type_descriptions
22
- end
23
-
24
- def label_from_file(default:)
25
- resource_files.find { |obj| obj.label.present? }&.label || default
26
- end
27
-
28
- def files
29
- resource_files.map { |file| File.new(file: file) }
30
- end
31
-
32
- private
33
-
34
- attr_reader :dpg, :resource_files, :style
35
-
36
- def special_dpg_resource?
37
- return false unless dpg
38
-
39
- resource_files.collect { |obj| ContentMetadata.special_dpg_folder?(obj.dpg_folder) }.include?(true)
40
- end
41
-
42
- # rubocop:disable Metrics/CyclomaticComplexity
43
- def resource_type_descriptions
44
- # grab all of the file types within a resource into an array so we can decide what the resource type should be
45
- resource_file_types = resource_files.collect(&:object_type)
46
- resource_has_non_images = !(resource_file_types - [:image]).empty?
47
-
48
- case style
49
- when :simple_image, :map, :'webarchive-seed'
50
- 'image'
51
- when :file
52
- 'file'
53
- when :simple_book # in a simple book project, all resources are pages unless they are *all* non-images -- if so, switch the type to object
54
- resource_has_non_images && resource_file_types.include?(:image) == false ? 'object' : 'page'
55
- when :book_as_image # same as simple book, but all resources are images instead of pages, unless we need to switch them to object type
56
- resource_has_non_images && resource_file_types.include?(:image) == false ? 'object' : 'image'
57
- when :book_with_pdf # in book with PDF type, if we find a resource with *any* non images, switch it's type from book to object
58
- resource_has_non_images ? 'object' : 'page'
59
- when :document
60
- 'document'
61
- when :'3d'
62
- resource_extensions = resource_files.collect(&:ext)
63
- if (resource_extensions & VALID_THREE_DIMENSION_EXTENTIONS).empty? # if this resource contains no known 3D file extensions, the resource type is file
64
- 'file'
65
- else # otherwise the resource type is 3d
66
- '3d'
67
- end
68
- end
69
- end
70
- # rubocop:enable Metrics/CyclomaticComplexity
71
- end
72
- end
73
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Assembly
4
- class ContentMetadata
5
- # Builds a groups of related Files, based on bundle
6
- class FileSetBuilder
7
- # @param [Symbol] bundle one of: :default, :filename, :dpg or :prebundled
8
- # @param [Array<Assembly::ObjectFile>] objects
9
- # @param [Symbol] style one of: :simple_image, :file, :simple_book, :book_as_image, :book_with_pdf, :map, or :'3d'
10
- def self.build(bundle:, objects:, style:)
11
- new(bundle: bundle, objects: objects, style: style).build
12
- end
13
-
14
- def initialize(bundle:, objects:, style:)
15
- @bundle = bundle
16
- @objects = objects
17
- @style = style
18
- end
19
-
20
- # @return [Array<FileSet>] a list of filesets in the object
21
- def build
22
- case bundle
23
- when :default # one resource per object
24
- objects.collect { |obj| FileSet.new(resource_files: [obj], style: style) }
25
- when :filename # one resource per distinct filename (excluding extension)
26
- build_for_filename
27
- when :dpg # group by DPG filename
28
- build_for_dpg
29
- when :prebundled
30
- # if the user specifies this method, they will pass in an array of arrays, indicating resources, so we don't need to bundle in the gem
31
- # This is used by the assemblyWF if you have stubContentMetadata.xml
32
- objects.map { |inner| FileSet.new(resource_files: inner, style: style) }
33
- else
34
- raise 'Invalid bundle method'
35
- end
36
- end
37
-
38
- private
39
-
40
- attr_reader :bundle, :objects, :style
41
-
42
- def build_for_filename
43
- # loop over distinct filenames, this determines how many resources we will have and
44
- # create one resource node per distinct filename, collecting the relevant objects with the distinct filename into that resource
45
- distinct_filenames = objects.collect(&:filename_without_ext).uniq # find all the unique filenames in the set of objects, leaving off extensions and base paths
46
- distinct_filenames.map do |distinct_filename|
47
- FileSet.new(resource_files: objects.collect { |obj| obj if obj.filename_without_ext == distinct_filename }.compact,
48
- style: style)
49
- end
50
- end
51
-
52
- def build_for_dpg
53
- # loop over distinct dpg base names, this determines how many resources we will have and
54
- # create one resource node per distinct dpg base name, collecting the relevant objects with the distinct names into that resource
55
-
56
- distinct_filenames = objects.collect(&:dpg_basename).uniq # find all the unique DPG filenames in the set of objects
57
- resources = distinct_filenames.map do |distinct_filename|
58
- FileSet.new(dpg: true, resource_files: objects.collect { |obj| obj if obj.dpg_basename == distinct_filename && !ContentMetadata.special_dpg_folder?(obj.dpg_folder) }.compact, style: style)
59
- end
60
- objects.each { |obj| resources << FileSet.new(dpg: true, resource_files: [obj], style: style) if ContentMetadata.special_dpg_folder?(obj.dpg_folder) } # certain subfolders require individual resources for files within them regardless of file-naming convention
61
- resources
62
- end
63
- end
64
- end
65
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Assembly
4
- class ContentMetadata
5
- # Builds a nokogiri representation of the content metadata
6
- class NokogiriBuilder
7
- # @param [Array<Fileset>] filesets
8
- # @param [String] druid
9
- # @param [String] common_path
10
- # @param [Config] config
11
- def self.build(filesets:, druid:, common_path:, config:)
12
- # a counter to use when creating auto-labels for resources, with incremenets for each type
13
- resource_type_counters = Hash.new(0)
14
- pid = druid.gsub('druid:', '') # remove druid prefix when creating IDs
15
-
16
- Nokogiri::XML::Builder.new do |xml|
17
- xml.contentMetadata(objectId: druid.to_s, type: config.type) do
18
- xml.bookData(readingOrder: config.reading_order) if config.type == 'book'
19
-
20
- filesets.each_with_index do |fileset, index| # iterate over all the resources
21
- # start a new resource element
22
- sequence = index + 1
23
-
24
- resource_type_counters[fileset.resource_type_description] += 1 # each resource type description gets its own incrementing counter
25
-
26
- xml.resource(id: "#{pid}_#{sequence}", sequence: sequence, type: fileset.resource_type_description) do
27
- # create a generic resource label if needed
28
- default_label = config.auto_labels ? "#{fileset.resource_type_description.capitalize} #{resource_type_counters[fileset.resource_type_description]}" : ''
29
-
30
- # but if one of the files has a label, use it instead
31
- resource_label = fileset.label_from_file(default: default_label)
32
-
33
- xml.label(resource_label) unless resource_label.empty?
34
- fileset.files.each do |obj| # iterate over all the files in a resource
35
- xml_file_params = { id: obj.file_id(common_path: common_path, flatten_folder_structure: config.flatten_folder_structure) }
36
- xml_file_params.merge!(obj.file_attributes(config.file_attributes)) if config.add_file_attributes
37
- xml_file_params.merge!(mimetype: obj.mimetype, size: obj.filesize) if config.add_exif
38
-
39
- xml.file(xml_file_params) do
40
- if config.add_exif # add exif info if the user requested it
41
- xml.checksum(obj.sha1, type: 'sha1')
42
- xml.checksum(obj.md5, type: 'md5')
43
- xml.imageData(obj.image_data) if obj.image? # add image data for an image
44
- elsif obj.provider_md5 || obj.provider_sha1 # if we did not add exif info, see if there are user supplied checksums to add
45
- xml.checksum(obj.provider_sha1, type: 'sha1') if obj.provider_sha1
46
- xml.checksum(obj.provider_md5, type: 'md5') if obj.provider_md5
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end