assembly-objectfile 1.7.2 → 1.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 833c781110e681cf9555ef036857efd1a4758902c8aea55f55f4e712e78470d1
4
- data.tar.gz: 83111a9c4145aac66c8e7ba24a07336c13cbf851407d05ad9a9d45d7bbf138d8
3
+ metadata.gz: fb34254f64779ebdf334f939519f151b6ffdf661588d194813efd2efa9e7d0fa
4
+ data.tar.gz: 98c7c49e243a5751002e68726f06665c210e7f360e10b08ef6f791abca3e00d9
5
5
  SHA512:
6
- metadata.gz: 9346400c4e01abece34de372d086037a60f3f0cf78479630986d0d25a346042e51dc8d6e8a6835f0b9dd5bf9e70fdbd4385a8689cbd9d9ddbd899142b60534ae
7
- data.tar.gz: 80cf1fa0011f28e08975d401c8d2ce3156485b4b4b3107b665d628679f1e9e4d4032313fb2434f5c7d24997f7004af6533f36b3f561560f284095264ff262a25
6
+ metadata.gz: 367d8abe3505708082bf7473a47e808195b6b12010c99a8227acdee0763e801f3018491593ad9071662a1903097c39740ab7ef8dbf94a2e404fc7abeee2b31c4
7
+ data.tar.gz: 443d63aa3187774914f0f61e71536f8612afea82414ded40293138e63446da452581e0f4e4a11f945ead2f7019a9722dcd8d054fd1669e04d64c0586827796db
@@ -108,23 +108,26 @@ module Assembly
108
108
  @sha1 ||= Digest::SHA1.file(path).hexdigest
109
109
  end
110
110
 
111
- # Returns mimetype information for the current file based on file extension or exif data (if available)
111
+ # Returns mimetype information for the current file based on
112
+ # (1) exifdata (if available), (2) unix file type or (3) file extension using the mimetypes gem, in this priority order
112
113
  # @return [String] mime type
113
114
  # @example
114
115
  # source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
115
116
  # puts source_file.mimetype # 'text/plain'
116
117
  def mimetype
117
118
  @mimetype ||= begin
118
- if exif && exif.mimetype # try exif first
119
- exif.mimetype
120
- else # otherwise get it from the mime-types gem (using the file extension), else blank
119
+ if exif_mimetype # first, try the exif data
120
+ exif_mimetype
121
+ elsif file_mimetype # next, try exif/unix file system command
122
+ file_mimetype
123
+ else # finally, get it from the mime-types gem (using the file extension) if both of those failed for some reason
121
124
  mtype = MIME::Types.type_for(path).first
122
125
  mtype ? mtype.content_type : ''
123
126
  end
124
127
  end
125
128
  end
126
129
 
127
- # Returns mimetype information for the current file based on unix file system command or exif data (if available).
130
+ # Returns mimetype information for the current file based on unix file system command.
128
131
  # @return [String] mime type for supplied file
129
132
  # @example
130
133
  # source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
@@ -132,9 +135,20 @@ module Assembly
132
135
  def file_mimetype
133
136
  @file_mimetype ||= begin
134
137
  check_for_file
135
- mtype = `file --mime-type "#{path}"`.delete("\n").split(':')[1].strip # first try and get the mimetype from the unix file command
136
- prefer_exif = !Assembly::TRUSTED_MIMETYPES.include?(mtype) && exif && exif.mimetype # if it's not a "trusted" mimetype and there is exif data; get the mimetype from the exif
137
- prefer_exif ? exif.mimetype : mtype
138
+ `file --mime-type "#{path}"`.delete("\n").split(':')[1].strip # first try and get the mimetype from the unix file command
139
+ end
140
+ end
141
+
142
+ # Returns mimetype information for the current file based on exif data (if available and not a trusted source that we'd rather get from the file system command)
143
+ # @return [String] mime type for supplied file
144
+ # @example
145
+ # source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
146
+ # puts source_file.exif_mimetype # 'text/plain'
147
+ def exif_mimetype
148
+ @exif_mimetype ||= begin
149
+ check_for_file
150
+ prefer_exif = !Assembly::TRUSTED_MIMETYPES.include?(file_mimetype) # if it's not a "trusted" mimetype and there is exif data; get the mimetype from the exif
151
+ exif.mimetype if exif && exif.mimetype && prefer_exif
138
152
  end
139
153
  end
140
154
 
@@ -2,6 +2,6 @@
2
2
  module Assembly
3
3
  class ObjectFile
4
4
  # Project version number
5
- VERSION = '1.7.2'.freeze
5
+ VERSION = '1.8.0'.freeze
6
6
  end
7
7
  end
@@ -36,6 +36,41 @@ describe Assembly::ObjectFile do
36
36
  expect(@ai.dirname).to eq(File.dirname(TEST_TIF_INPUT_FILE))
37
37
  end
38
38
 
39
+ it 'sets the correct mimetype of plain/text for .txt files' do
40
+ @ai = described_class.new(TEST_RES1_TEXT)
41
+ expect(@ai.mimetype).to eq('text/plain')
42
+ end
43
+
44
+ it 'sets the correct mimetype of plain/text for .xml files' do
45
+ @ai = described_class.new(TEST_RES1_TEXT)
46
+ expect(@ai.mimetype).to eq('text/plain')
47
+ end
48
+
49
+ it 'sets the correct mimetype of plain/text for .obj 3d files' do
50
+ @ai = described_class.new(TEST_OBJ_FILE)
51
+ expect(@ai.mimetype).to eq('text/plain')
52
+ end
53
+
54
+ it 'sets the correct mimetype of plain/text for .ply 3d files' do
55
+ @ai = described_class.new(TEST_PLY_FILE)
56
+ expect(@ai.mimetype).to eq('text/plain')
57
+ end
58
+
59
+ it 'sets the correct mimetype of image/tiff for .tif files' do
60
+ @ai = described_class.new(TEST_TIF_INPUT_FILE)
61
+ expect(@ai.mimetype).to eq('image/tiff')
62
+ end
63
+
64
+ it 'sets the correct mimetype of image/jp2 for .jp2 files' do
65
+ @ai = described_class.new(TEST_JP2_INPUT_FILE)
66
+ expect(@ai.mimetype).to eq('image/jp2')
67
+ end
68
+
69
+ it 'sets the correct mimetype of application/pdf for .pdf files' do
70
+ @ai = described_class.new(TEST_RES1_PDF)
71
+ expect(@ai.mimetype).to eq('application/pdf')
72
+ end
73
+
39
74
  it 'gives us the mimetype of a file even if the exif information is damaged' do
40
75
  @ai = described_class.new(TEST_FILE_NO_EXIF)
41
76
  expect(@ai.filename).to eq('file_with_no_exif.xml')
@@ -141,7 +176,7 @@ describe Assembly::ObjectFile do
141
176
  expect(File.exist?(non_image_file)).to be true
142
177
  @ai = described_class.new(non_image_file)
143
178
  expect(@ai.image?).to eq(false)
144
- expect(@ai.object_type).to eq(:other)
179
+ expect(@ai.object_type).not_to eq(:image)
145
180
  expect(@ai.valid_image?).to eq(false)
146
181
  end
147
182
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assembly-objectfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2019-08-14 00:00:00.000000000 Z
14
+ date: 2019-08-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: mime-types