assembly-objectfile 1.8.4 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55d4581c113766a963826ca6e77b15edcab495dfe1a58d029515ac63f71dab61
4
- data.tar.gz: 6345774179c1af7b1bb179dcb079c79f0c48d15418d15b6c9a8010d2a81d66a8
3
+ metadata.gz: 04ee4aa95c21e1ef894bc760f83bf38bc4ce18cb18ca543451fc9645ee43f20b
4
+ data.tar.gz: e6e6f2a9a6d9e075470f412bcd299d4da9dbeb3e5aa673c6b371e3d20c3e06fc
5
5
  SHA512:
6
- metadata.gz: 834d7062c0f3ffa547d5c88e051a5148598cbd6ec0debc9b0318da8c97725e9b136ee5cacbd64b49d1cf5e0bd7481ae4eaa5061e9b247772915b821f2af1c0d3
7
- data.tar.gz: 3c2b9d1496af4400a57b383de90df51b02775e6f15afb6ca869607a4c890dd489cd932f99f473fb346de7fea81121e731ab1e04fb7c58dd4f6ee77bedda37ae3
6
+ metadata.gz: 23c5882333d2c6b95eb107672c374986c8b048d9844ed40c8716cae9f1d8ad4a1904c187f0bdc308ac97262010a0e386eaae833524100fd4de7d8f9dcf672c23
7
+ data.tar.gz: 15114a44a00b614f41d6cb8467c1fbaf16986dc570ed7e4decc574eebfdc1fe52321fc8c87cce37ba45199347860b47044ea8fde6467e4399569ac6c84eafe77
@@ -38,7 +38,7 @@ Metrics/MethodLength:
38
38
  # Offense count: 1
39
39
  # Configuration parameters: CountComments.
40
40
  Metrics/ModuleLength:
41
- Max: 107
41
+ Max: 117
42
42
 
43
43
  # Offense count: 1
44
44
  # Configuration parameters: CountKeywordArgs.
@@ -7,7 +7,7 @@ module Assembly
7
7
  # Represents a groups of related Files, such as a single master file and the derivatives
8
8
  class FileSet
9
9
  # @param [Boolean] dpg (false) is it a dpg bundle?
10
- # @param [Array] resource_files
10
+ # @param [Array<Assembly::ObjectFile>] resource_files
11
11
  # @param style
12
12
  def initialize(dpg: false, resource_files:, style:)
13
13
  @dpg = dpg
@@ -4,6 +4,9 @@ module Assembly
4
4
  class ContentMetadata
5
5
  # Builds a groups of related Files, based on bundle
6
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'
7
10
  def self.build(bundle:, objects:, style:)
8
11
  new(bundle: bundle, objects: objects, style: style).build
9
12
  end
@@ -25,6 +28,7 @@ module Assembly
25
28
  build_for_dpg
26
29
  when :prebundled
27
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
28
32
  objects.map { |inner| FileSet.new(resource_files: inner, style: style) }
29
33
  else
30
34
  raise 'Invalid bundle method'
@@ -2,12 +2,12 @@
2
2
 
3
3
  require 'mini_exiftool'
4
4
  require 'mime/types'
5
- # require 'checksum-tools'
6
5
 
7
6
  module Assembly
8
7
  # Common behaviors we need for other classes in the gem
9
8
  module ObjectFileable
10
- attr_accessor :file_attributes, :label, :path, :provider_md5, :provider_sha1, :relative_path
9
+ attr_accessor :file_attributes, :label, :path, :provider_md5, :provider_sha1, :relative_path, :mime_type_order
10
+ VALID_MIMETYPE_METHODS = %i[exif file extension].freeze
11
11
 
12
12
  # @param [String] path full path to the file to be worked with
13
13
  # @param [Hash<Symbol => Object>] params options used during content metadata generation
@@ -16,6 +16,9 @@ module Assembly
16
16
  # @option params [String] :provider_md5 pre-computed MD5 checksum
17
17
  # @option params [String] :provider_sha1 pre-computed SHA1 checksum
18
18
  # @option params [String] :relative_path if you want the file ids in the content metadata it can be set, otherwise content metadata will get the full path
19
+ # @option params [Array] :mime_type_order can be set to the order in which you want mimetypes to be determined
20
+ # options are :exif (from exif if exists), :extension (from file extension), and :file (from unix file system command)
21
+ # the default is defined in the private `default_mime_type_order` method but you can override to set your own order
19
22
  # @example
20
23
  # Assembly::ObjectFile.new('/input/path_to_file.tif')
21
24
  def initialize(path, params = {})
@@ -25,6 +28,7 @@ module Assembly
25
28
  @relative_path = params[:relative_path]
26
29
  @provider_md5 = params[:provider_md5]
27
30
  @provider_sha1 = params[:provider_sha1]
31
+ @mime_type_order = params[:mime_type_order] || default_mime_type_order
28
32
  end
29
33
 
30
34
  # @return [String] DPG base filename, removing the extension and the '00','05', etc. placeholders
@@ -110,22 +114,33 @@ module Assembly
110
114
  @sha1 ||= Digest::SHA1.file(path).hexdigest
111
115
  end
112
116
 
113
- # Returns mimetype information for the current file based on
114
- # (1) exifdata (if available), (2) unix file type or (3) file extension using the mimetypes gem, in this priority order
117
+ # Returns mimetype information for the current file based on the ordering set in default_mime_type_order
118
+ # We stop computing mimetypes as soon as we have a method that returns a value
115
119
  # @return [String] mime type
116
120
  # @example
117
121
  # source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
118
122
  # puts source_file.mimetype # 'text/plain'
119
123
  def mimetype
120
124
  @mimetype ||= begin
121
- if exif_mimetype # first, try the exif data
122
- exif_mimetype
123
- elsif file_mimetype # next, try exif/unix file system command
124
- file_mimetype
125
- else # finally, get it from the mime-types gem (using the file extension) if both of those failed for some reason
126
- mtype = MIME::Types.type_for(path).first
127
- mtype ? mtype.content_type : ''
125
+ check_for_file
126
+ mimetype = ''
127
+ mime_type_order.each do |mime_type_method|
128
+ mimetype = public_send("#{mime_type_method}_mimetype") if VALID_MIMETYPE_METHODS.include?(mime_type_method)
129
+ break if !mimetype.nil? && mimetype != ''
128
130
  end
131
+ mimetype
132
+ end
133
+ end
134
+
135
+ # Returns mimetype information using the mime-types gem (based on a file extension lookup)
136
+ # @return [String] mime type for supplied file
137
+ # @example
138
+ # source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
139
+ # puts source_file.extension_mimetype # 'text/plain'
140
+ def extension_mimetype
141
+ @extension_mimetype ||= begin
142
+ mtype = MIME::Types.type_for(path).first
143
+ mtype ? mtype.content_type : ''
129
144
  end
130
145
  end
131
146
 
@@ -234,11 +249,16 @@ exif&.mimetype && prefer_exif
234
249
  # source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
235
250
  # puts source_file.file_exists? # true
236
251
  def file_exists?
237
- File.exist?(path) && !File.directory?(path)
252
+ @file_exists ||= (File.exist?(path) && !File.directory?(path))
238
253
  end
239
254
 
240
255
  private
241
256
 
257
+ # prive method defining default preferred ordering of how mimetypes are determined
258
+ def default_mime_type_order
259
+ %i[exif file extension]
260
+ end
261
+
242
262
  # private method to check for file existence before operating on it
243
263
  def check_for_file
244
264
  raise "input file #{path} does not exist" unless file_exists?
@@ -4,6 +4,6 @@
4
4
  module Assembly
5
5
  class ObjectFile
6
6
  # Project version number
7
- VERSION = '1.8.4'
7
+ VERSION = '1.9.0'
8
8
  end
9
9
  end
@@ -25,6 +25,8 @@ describe Assembly::ObjectFile do
25
25
  expect(@ai.exif).not_to be nil
26
26
  expect(@ai.mimetype).to eq('image/tiff')
27
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')
28
30
  expect(@ai.object_type).to eq(:image)
29
31
  expect(@ai.valid_image?).to eq(true)
30
32
  expect(@ai.jp2able?).to eq(true)
@@ -53,6 +55,16 @@ describe Assembly::ObjectFile do
53
55
  expect(@ai.mimetype).to eq('text/plain')
54
56
  end
55
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
+
56
68
  it 'sets the correct mimetype of plain/text for .ply 3d files' do
57
69
  @ai = described_class.new(TEST_PLY_FILE)
58
70
  expect(@ai.mimetype).to eq('text/plain')
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.8.4
4
+ version: 1.9.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: 2020-01-21 00:00:00.000000000 Z
14
+ date: 2020-02-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -273,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
273
  - !ruby/object:Gem::Version
274
274
  version: '0'
275
275
  requirements: []
276
- rubygems_version: 3.1.2
276
+ rubygems_version: 3.0.3
277
277
  signing_key:
278
278
  specification_version: 4
279
279
  summary: Ruby immplementation of file services needed to prepare objects to be accessioned