assembly-objectfile 1.12.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -0
  3. data/.github/pull_request_template.md +1 -1
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +117 -12
  6. data/.rubocop_todo.yml +3 -109
  7. data/Gemfile.lock +97 -0
  8. data/README.md +7 -7
  9. data/assembly-objectfile.gemspec +8 -11
  10. data/config/boot.rb +0 -1
  11. data/lib/{assembly-objectfile → assembly/object_file}/version.rb +2 -2
  12. data/lib/{assembly-objectfile/object_fileable.rb → assembly/object_file.rb} +109 -104
  13. data/lib/assembly-objectfile.rb +12 -15
  14. data/spec/assembly/object_file_spec.rb +451 -0
  15. data/spec/spec_helper.rb +2 -31
  16. data/spec/test_data/empty.txt +0 -0
  17. metadata +23 -156
  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_file.rb +0 -29
  26. data/profiles/AdobeRGB1998.icc +0 -0
  27. data/profiles/DotGain20.icc +0 -0
  28. data/profiles/sRGBIEC6196621.icc +0 -0
  29. data/spec/content_metadata_spec.rb +0 -809
  30. data/spec/object_file_spec.rb +0 -217
  31. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  32. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  33. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  34. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  35. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  36. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  37. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  38. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  39. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  40. data/spec/test_data/input/res1_image1.jp2 +0 -0
  41. data/spec/test_data/input/res1_image2.jp2 +0 -0
  42. data/spec/test_data/input/res1_image2.tif +0 -0
  43. data/spec/test_data/input/res1_teifile.txt +0 -1
  44. data/spec/test_data/input/res2_image1.jp2 +0 -0
  45. data/spec/test_data/input/res2_image1.tif +0 -0
  46. data/spec/test_data/input/res2_image2.jp2 +0 -0
  47. data/spec/test_data/input/res2_image2.tif +0 -0
  48. data/spec/test_data/input/res2_teifile.txt +0 -1
  49. data/spec/test_data/input/res2_textfile.txt +0 -1
  50. data/spec/test_data/input/res3_image1.jp2 +0 -0
  51. data/spec/test_data/input/res3_image1.tif +0 -0
  52. data/spec/test_data/input/res3_teifile.txt +0 -1
  53. data/spec/test_data/input/test.pdf +0 -1
  54. data/spec/test_data/input/test.svg +0 -2
  55. data/spec/test_data/input/test2.jp2 +0 -0
  56. data/spec/test_data/input/test2.tif +0 -0
@@ -1,217 +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
- @ai = described_class.new('')
8
- expect { @ai.filesize }.to raise_error(RuntimeError, 'input file does not exist')
9
- expect { @ai.sha1 }.to raise_error(RuntimeError, 'input file does not exist')
10
- expect { @ai.md5 }.to raise_error(RuntimeError, 'input file does not exist')
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
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
24
- expect(@ai.image?).to eq(true)
25
- expect(@ai.exif).not_to be nil
26
- expect(@ai.mimetype).to eq('image/tiff')
27
- expect(@ai.file_mimetype).to eq('image/tiff')
28
- expect(@ai.extension_mimetype).to eq('image/tiff')
29
- expect(@ai.exif_mimetype).to eq('image/tiff')
30
- expect(@ai.object_type).to eq(:image)
31
- expect(@ai.valid_image?).to eq(true)
32
- expect(@ai.jp2able?).to eq(true)
33
- end
34
-
35
- it 'tells us information about the input file' do
36
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
37
- expect(@ai.filename).to eq('test.tif')
38
- expect(@ai.ext).to eq('.tif')
39
- expect(@ai.filename_without_ext).to eq('test')
40
- expect(@ai.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
- @ai = described_class.new(TEST_RES1_TEXT)
45
- expect(@ai.mimetype).to eq('text/plain')
46
- end
47
-
48
- it 'sets the correct mimetype of plain/text for .xml files' do
49
- @ai = described_class.new(TEST_RES1_TEXT)
50
- expect(@ai.mimetype).to eq('text/plain')
51
- end
52
-
53
- it 'sets the correct mimetype of plain/text for .obj 3d files' do
54
- @ai = described_class.new(TEST_OBJ_FILE)
55
- expect(@ai.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
- @ai = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[extension file exif])
60
- expect(@ai.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
- @ai = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[bogus extension file])
65
- expect(@ai.mimetype).to eq('application/x-tgif')
66
- end
67
-
68
- it 'sets the correct mimetype of plain/text for .ply 3d files' do
69
- @ai = described_class.new(TEST_PLY_FILE)
70
- expect(@ai.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
- @ai = described_class.new(TEST_JSON_FILE)
75
- expect(@ai.exif_mimetype).to be_nil # exif returns nil
76
- expect(@ai.file_mimetype).to eq('text/plain') # unix file system command returns plain text
77
- expect(@ai.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
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
82
- expect(@ai.mimetype).to eq('image/tiff')
83
- end
84
-
85
- it 'sets the correct mimetype of image/jp2 for .jp2 files' do
86
- @ai = described_class.new(TEST_JP2_INPUT_FILE)
87
- expect(@ai.mimetype).to eq('image/jp2')
88
- end
89
-
90
- it 'sets the correct mimetype of application/pdf for .pdf files' do
91
- @ai = described_class.new(TEST_RES1_PDF)
92
- expect(@ai.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
- @ai = described_class.new(TEST_FILE_NO_EXIF)
97
- expect(@ai.filename).to eq('file_with_no_exif.xml')
98
- expect(@ai.ext).to eq('.xml')
99
- expect(['text/html', 'application/xml'].include?(@ai.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
- @ai = described_class.new(test_file)
105
- expect(@ai.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
- @ai = described_class.new(test_file)
111
- expect(@ai.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
- @ai = described_class.new(TEST_JP2_INPUT_FILE)
117
- expect(@ai.image?).to eq(true)
118
- expect(@ai.object_type).to eq(:image)
119
- expect(@ai.valid_image?).to eq(true)
120
- expect(@ai.jp2able?).to eq(false)
121
- expect(@ai.has_color_profile?).to eq(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
- @ai = described_class.new(TEST_RES1_TIF1)
127
- expect(@ai.image?).to eq(true)
128
- expect(@ai.object_type).to eq(:image)
129
- expect(@ai.valid_image?).to eq(true)
130
- expect(@ai.jp2able?).to eq(true)
131
- expect(@ai.has_color_profile?).to eq(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
- @ai = described_class.new(TEST_TIFF_NO_COLOR_FILE)
137
- expect(@ai.image?).to eq(true)
138
- expect(@ai.object_type).to eq(:image)
139
- expect(@ai.valid_image?).to eq(true)
140
- expect(@ai.jp2able?).to eq(true)
141
- expect(@ai.has_color_profile?).to eq(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
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
147
- expect(@ai.md5).to eq('a2400500acf21e43f5440d93be894101')
148
- expect(@ai.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
- @ai = described_class.new(path)
154
- expect(File.exist?(path)).to be true
155
- expect(File.directory?(path)).to be true
156
- expect(@ai.file_exists?).to be false
157
-
158
- path = File.join(Assembly::PATH_TO_GEM, 'bogus.txt')
159
- @ai = described_class.new(path)
160
- expect(File.exist?(path)).to be false
161
- expect(File.directory?(path)).to be false
162
- expect(@ai.file_exists?).to be false
163
- end
164
-
165
- it 'sets attributes correctly when initializing' do
166
- @ai = described_class.new('/some/file.txt')
167
- expect(@ai.path).to eq('/some/file.txt')
168
- expect(@ai.label).to be_nil
169
- expect(@ai.file_attributes).to be_nil
170
- expect(@ai.provider_sha1).to be_nil
171
- expect(@ai.provider_md5).to be_nil
172
- expect(@ai.relative_path).to be_nil
173
-
174
- @ai = described_class.new('/some/file.txt', label: 'some label', file_attributes: { 'shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no' }, relative_path: '/tmp')
175
- expect(@ai.path).to eq('/some/file.txt')
176
- expect(@ai.label).to eq('some label')
177
- expect(@ai.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
178
- expect(@ai.provider_sha1).to be_nil
179
- expect(@ai.provider_md5).to be_nil
180
- expect(@ai.relative_path).to eq('/tmp')
181
- end
182
-
183
- it 'sets md5_provider attribute' do
184
- ai = described_class.new('/some/file.txt', provider_md5: 'XYZ')
185
- expect(ai.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
- @ai = described_class.new(non_image_file)
192
- expect(@ai.image?).to eq(false)
193
- expect(@ai.object_type).not_to eq(:image)
194
- expect(@ai.valid_image?).to eq(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
- @ai = described_class.new(non_image_file)
199
- expect(@ai.image?).to eq(false)
200
- expect(@ai.object_type).not_to eq(:image)
201
- expect(@ai.valid_image?).to eq(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
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
207
- expect(@ai.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
- 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