assembly-objectfile 1.13.0 → 2.1.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +34 -1
  5. data/.rubocop_todo.yml +3 -120
  6. data/Gemfile.lock +97 -0
  7. data/README.md +6 -6
  8. data/assembly-objectfile.gemspec +4 -8
  9. data/config/boot.rb +0 -1
  10. data/lib/{assembly-objectfile → assembly/object_file}/version.rb +1 -1
  11. data/lib/{assembly-objectfile/object_fileable.rb → assembly/object_file.rb} +116 -101
  12. data/lib/assembly-objectfile.rb +14 -19
  13. data/spec/assembly/object_file_spec.rb +452 -0
  14. data/spec/spec_helper.rb +3 -37
  15. metadata +10 -143
  16. data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
  17. data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
  18. data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
  19. data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
  20. data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
  21. data/lib/assembly-objectfile/content_metadata.rb +0 -117
  22. data/lib/assembly-objectfile/object_file.rb +0 -29
  23. data/profiles/AdobeRGB1998.icc +0 -0
  24. data/profiles/DotGain20.icc +0 -0
  25. data/profiles/sRGBIEC6196621.icc +0 -0
  26. data/spec/content_metadata_spec.rb +0 -809
  27. data/spec/object_file_spec.rb +0 -222
  28. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  29. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  30. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  31. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  32. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  33. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  34. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  35. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  36. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  37. data/spec/test_data/input/res1_image1.jp2 +0 -0
  38. data/spec/test_data/input/res1_image2.jp2 +0 -0
  39. data/spec/test_data/input/res1_image2.tif +0 -0
  40. data/spec/test_data/input/res1_teifile.txt +0 -1
  41. data/spec/test_data/input/res2_image1.jp2 +0 -0
  42. data/spec/test_data/input/res2_image1.tif +0 -0
  43. data/spec/test_data/input/res2_image2.jp2 +0 -0
  44. data/spec/test_data/input/res2_image2.tif +0 -0
  45. data/spec/test_data/input/res2_teifile.txt +0 -1
  46. data/spec/test_data/input/res2_textfile.txt +0 -1
  47. data/spec/test_data/input/res3_image1.jp2 +0 -0
  48. data/spec/test_data/input/res3_image1.tif +0 -0
  49. data/spec/test_data/input/res3_teifile.txt +0 -1
  50. data/spec/test_data/input/test.pdf +0 -1
  51. data/spec/test_data/input/test.svg +0 -2
  52. data/spec/test_data/input/test2.jp2 +0 -0
  53. data/spec/test_data/input/test2.tif +0 -0
@@ -1,222 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Assembly::ObjectFile do
6
- it 'does not run if no input file is passed in' do
7
- object_file = described_class.new('')
8
- expect { object_file.filesize }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
9
- expect { object_file.sha1 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
10
- expect { object_file.md5 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
11
- end
12
-
13
- it 'returns the common directory of a set of filenames passed into it, where the common part does not terminate on a directory' do
14
- expect(described_class.common_path(['/Users/peter/00/test.tif', '/Users/peter/05/test.jp2'])).to eq('/Users/peter/')
15
- end
16
-
17
- it 'returns the common directory of a set of filenames passed into it, where the common part does not terminate on a directory' do
18
- expect(described_class.common_path(['/Users/peter/00/test.tif', '/Users/peter/00/test.jp2'])).to eq('/Users/peter/00/')
19
- end
20
-
21
- it 'tells us if an input file is an image' do
22
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
23
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
24
- expect(object_file.image?).to be(true)
25
- expect(object_file.exif).not_to be_nil
26
- expect(object_file.mimetype).to eq('image/tiff')
27
- expect(object_file.file_mimetype).to eq('image/tiff')
28
- expect(object_file.extension_mimetype).to eq('image/tiff')
29
- expect(object_file.exif_mimetype).to eq('image/tiff')
30
- expect(object_file.object_type).to eq(:image)
31
- expect(object_file.valid_image?).to be(true)
32
- expect(object_file.jp2able?).to be(true)
33
- end
34
-
35
- it 'tells us information about the input file' do
36
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
37
- expect(object_file.filename).to eq('test.tif')
38
- expect(object_file.ext).to eq('.tif')
39
- expect(object_file.filename_without_ext).to eq('test')
40
- expect(object_file.dirname).to eq(File.dirname(TEST_TIF_INPUT_FILE))
41
- end
42
-
43
- it 'sets the correct mimetype of plain/text for .txt files' do
44
- object_file = described_class.new(TEST_RES1_TEXT)
45
- expect(object_file.mimetype).to eq('text/plain')
46
- end
47
-
48
- it 'sets the correct mimetype of plain/text for .xml files' do
49
- object_file = described_class.new(TEST_RES1_TEXT)
50
- expect(object_file.mimetype).to eq('text/plain')
51
- end
52
-
53
- it 'sets the correct mimetype of plain/text for .obj 3d files' do
54
- object_file = described_class.new(TEST_OBJ_FILE)
55
- expect(object_file.mimetype).to eq('text/plain')
56
- end
57
-
58
- it 'sets a mimetype of application/x-tgif for .obj 3d files if we prefer the mimetype extension gem over unix file system command' do
59
- object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[extension file exif])
60
- expect(object_file.mimetype).to eq('application/x-tgif')
61
- end
62
-
63
- it 'ignores invald mimetype generation methods and still sets a mimetype of application/x-tgif for .obj 3d files if we prefer the mimetype extension gem over unix file system command' do
64
- object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[bogus extension file])
65
- expect(object_file.mimetype).to eq('application/x-tgif')
66
- end
67
-
68
- it 'sets the correct mimetype of plain/text for .ply 3d files' do
69
- object_file = described_class.new(TEST_PLY_FILE)
70
- expect(object_file.mimetype).to eq('text/plain')
71
- end
72
-
73
- it 'overrides the mimetype generators and uses the manual mapping to set the correct mimetype of application/json for a .json file' do
74
- object_file = described_class.new(TEST_JSON_FILE)
75
- expect(object_file.exif_mimetype).to be_nil # exif returns nil
76
- expect(object_file.file_mimetype).to eq('text/plain') # unix file system command returns plain text
77
- expect(object_file.mimetype).to eq('application/json') # but our configured mapping overrides both and returns application/json
78
- end
79
-
80
- it 'sets the correct mimetype of image/tiff for .tif files' do
81
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
82
- expect(object_file.mimetype).to eq('image/tiff')
83
- end
84
-
85
- it 'sets the correct mimetype of image/jp2 for .jp2 files' do
86
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
87
- expect(object_file.mimetype).to eq('image/jp2')
88
- end
89
-
90
- it 'sets the correct mimetype of application/pdf for .pdf files' do
91
- object_file = described_class.new(TEST_RES1_PDF)
92
- expect(object_file.mimetype).to eq('application/pdf')
93
- end
94
-
95
- it 'gives us the mimetype of a file even if the exif information is damaged' do
96
- object_file = described_class.new(TEST_FILE_NO_EXIF)
97
- expect(object_file.filename).to eq('file_with_no_exif.xml')
98
- expect(object_file.ext).to eq('.xml')
99
- expect(['text/html', 'application/xml'].include?(object_file.mimetype)).to be true # we could get either of these mimetypes depending on the OS
100
- end
101
-
102
- it 'gives us the DPG base name for a file' do
103
- test_file = File.join(TEST_INPUT_DIR, 'oo000oo0001_00_001.tif')
104
- object_file = described_class.new(test_file)
105
- expect(object_file.dpg_basename).to eq('oo000oo0001_001')
106
- end
107
-
108
- it 'gives us the DPG subfolder name for a file' do
109
- test_file = File.join(TEST_INPUT_DIR, 'oo000oo0001_05_001.tif')
110
- object_file = described_class.new(test_file)
111
- expect(object_file.dpg_folder).to eq('05')
112
- end
113
-
114
- it 'tells us that a jp2 file is not jp2able but does have a color profile' do
115
- expect(File.exist?(TEST_JP2_INPUT_FILE)).to be true
116
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
117
- expect(object_file.image?).to be(true)
118
- expect(object_file.object_type).to eq(:image)
119
- expect(object_file.valid_image?).to be(true)
120
- expect(object_file.jp2able?).to be(false)
121
- expect(object_file.has_color_profile?).to be(true)
122
- end
123
-
124
- it 'tells us that a tiff file is jp2able and has a color profile' do
125
- expect(File.exist?(TEST_RES1_TIF1)).to be true
126
- object_file = described_class.new(TEST_RES1_TIF1)
127
- expect(object_file.image?).to be(true)
128
- expect(object_file.object_type).to eq(:image)
129
- expect(object_file.valid_image?).to be(true)
130
- expect(object_file.jp2able?).to be(true)
131
- expect(object_file.has_color_profile?).to be(true)
132
- end
133
-
134
- it 'tells us that a tiff file is not jp2able and is not valid since it has no profile' do
135
- expect(File.exist?(TEST_TIFF_NO_COLOR_FILE)).to be true
136
- object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
137
- expect(object_file.image?).to be(true)
138
- expect(object_file.object_type).to eq(:image)
139
- expect(object_file.valid_image?).to be(true)
140
- expect(object_file.jp2able?).to be(true)
141
- expect(object_file.has_color_profile?).to be(false)
142
- end
143
-
144
- it 'computes checksums for an image file' do
145
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
146
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
147
- expect(object_file.md5).to eq('a2400500acf21e43f5440d93be894101')
148
- expect(object_file.sha1).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
149
- end
150
-
151
- it 'indicates that the file is not found when a valid directory is supplied instead of a file or when an invalid file path is specified' do
152
- path = Assembly::PATH_TO_GEM
153
- object_file = described_class.new(path)
154
- expect(File.exist?(path)).to be true
155
- expect(File.directory?(path)).to be true
156
- expect(object_file.file_exists?).to be false
157
-
158
- path = File.join(Assembly::PATH_TO_GEM, 'bogus.txt')
159
- object_file = described_class.new(path)
160
- expect(File.exist?(path)).to be false
161
- expect(File.directory?(path)).to be false
162
- expect(object_file.file_exists?).to be false
163
- end
164
-
165
- it 'sets attributes correctly when initializing' do
166
- object_file = described_class.new('/some/file.txt')
167
- expect(object_file.path).to eq('/some/file.txt')
168
- expect(object_file.label).to be_nil
169
- expect(object_file.file_attributes).to be_nil
170
- expect(object_file.provider_sha1).to be_nil
171
- expect(object_file.provider_md5).to be_nil
172
- expect(object_file.relative_path).to be_nil
173
-
174
- object_file = described_class.new('/some/file.txt', label: 'some label', file_attributes: { 'shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no' }, relative_path: '/tmp')
175
- expect(object_file.path).to eq('/some/file.txt')
176
- expect(object_file.label).to eq('some label')
177
- expect(object_file.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
178
- expect(object_file.provider_sha1).to be_nil
179
- expect(object_file.provider_md5).to be_nil
180
- expect(object_file.relative_path).to eq('/tmp')
181
- end
182
-
183
- it 'sets md5_provider attribute' do
184
- object_file = described_class.new('/some/file.txt', provider_md5: 'XYZ')
185
- expect(object_file.provider_md5).to eq('XYZ')
186
- end
187
-
188
- it 'tells us if an input file is not an image' do
189
- non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/object_file_spec.rb')
190
- expect(File.exist?(non_image_file)).to be true
191
- object_file = described_class.new(non_image_file)
192
- expect(object_file.image?).to be(false)
193
- expect(object_file.object_type).not_to eq(:image)
194
- expect(object_file.valid_image?).to be(false)
195
-
196
- non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
197
- expect(File.exist?(non_image_file)).to be true
198
- object_file = described_class.new(non_image_file)
199
- expect(object_file.image?).to be(false)
200
- expect(object_file.object_type).not_to eq(:image)
201
- expect(object_file.valid_image?).to be(false)
202
- end
203
-
204
- it 'tells us the size of an input file' do
205
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
206
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
207
- expect(object_file.filesize).to eq(63_542)
208
- end
209
-
210
- it 'tells us the mimetype and encoding of an input file' do
211
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
212
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
213
- expect(@ai.mimetype).to eq('image/tiff')
214
- expect(@ai.file_mimetype).to eq('image/tiff')
215
- expect(@ai.encoding).to eq('binary')
216
- end
217
-
218
- it 'raises MiniExiftool::Error if exiftool raises one' do
219
- object_file = described_class.new('spec/test_data/empty.txt')
220
- expect { object_file.exif }.to raise_error(MiniExiftool::Error)
221
- end
222
- end
@@ -1 +0,0 @@
1
- Fake file: Transcript/aa111aa1111.pdf
@@ -1 +0,0 @@
1
- Fake file: Transcript/aa111aa1111.pdf
@@ -1 +0,0 @@
1
- Fake file: Transcript/aa111aa1111.pdf
@@ -1 +0,0 @@
1
- Fake file: Transcript/aa111aa1111.pdf
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- this is another text file for resource 1
Binary file
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- this is another text file for resource 2
@@ -1 +0,0 @@
1
- this is a text file for resource 2
Binary file
Binary file
@@ -1 +0,0 @@
1
- this is another text file for resource 3
@@ -1 +0,0 @@
1
- Fake file: Transcript/aa111aa1111.pdf
@@ -1,2 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <svg width="507.3" height="508.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="hidden"><defs><clipPath id="clip0"><rect x="2361" y="213" width="507" height="508"/></clipPath></defs><g clip-path="url(#clip0)" transform="translate(-2361 -213)"><path d="M2361 467C2361 326.72 2474.5 213 2614.5 213 2754.5 213 2868 326.72 2868 467 2868 607.28 2754.5 721 2614.5 721 2474.5 721 2361 607.28 2361 467Z" fill="#BF9000" fill-rule="evenodd"/></g></svg>
Binary file
Binary file