libis-format 1.2.8 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/data/types.yml +1 -1
  4. data/lib/libis/format/command_line.rb +2 -3
  5. data/lib/libis/format/config.rb +18 -19
  6. data/lib/libis/format/converter/base.rb +9 -16
  7. data/lib/libis/format/converter/chain.rb +36 -28
  8. data/lib/libis/format/converter/email_converter.rb +5 -8
  9. data/lib/libis/format/converter/fop_pdf_converter.rb +4 -6
  10. data/lib/libis/format/converter/image_converter.rb +51 -58
  11. data/lib/libis/format/converter/jp2_converter.rb +33 -35
  12. data/lib/libis/format/converter/office_converter.rb +19 -23
  13. data/lib/libis/format/converter/pdf_converter.rb +22 -28
  14. data/lib/libis/format/converter/repository.rb +7 -13
  15. data/lib/libis/format/converter/spreadsheet_converter.rb +7 -11
  16. data/lib/libis/format/converter/video_converter.rb +41 -55
  17. data/lib/libis/format/converter/xslt_converter.rb +14 -13
  18. data/lib/libis/format/converter.rb +1 -1
  19. data/lib/libis/format/identifier.rb +41 -43
  20. data/lib/libis/format/tool/droid.rb +29 -30
  21. data/lib/libis/format/tool/ff_mpeg.rb +11 -13
  22. data/lib/libis/format/tool/fido.rb +1 -1
  23. data/lib/libis/format/tool/pdf_copy.rb +17 -18
  24. data/lib/libis/format/tool/pdf_merge.rb +17 -17
  25. data/lib/libis/format/tool/pdf_optimizer.rb +18 -20
  26. data/lib/libis/format/tool/spreadsheet_to_ods.rb +23 -20
  27. data/lib/libis/format/tool.rb +2 -2
  28. data/lib/libis/format/type_database.rb +51 -28
  29. data/lib/libis/format/type_database_impl.rb +57 -24
  30. data/lib/libis/format/version.rb +1 -1
  31. data/lib/libis/format.rb +3 -2
  32. data/lib/libis-format.rb +2 -0
  33. data/libis-format.gemspec +1 -1
  34. metadata +17 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573be9f0abbf23c061f313ac800ea1d24a930b31038fdba2810e39e8383e0ee8
4
- data.tar.gz: 26f481ef822822ff376049fc8cfffe922e30f55bec9c6c5b26ebdb1a7141ec60
3
+ metadata.gz: b8282db4cf37eea292436474d401bcc2725c31eaa1eb882ea9475be14912f6c9
4
+ data.tar.gz: 6eaf1dfe05d24bd0df1ad20f61137a4007f02828b97138601c87afc5215d7454
5
5
  SHA512:
6
- metadata.gz: 1413ea4713b2bc5b891670414b618f3598421d265f2abac1ba1c2dd474eef3006334d02e195fbf03846d4b6e0b153e8b0503bb1b82d0c349b024917a9093ce27
7
- data.tar.gz: e501e85571c11174b269ccdf853a72604856dd5ccf31f45a17796b19d41b064a5a85a6fd35774e009837f29649af0918f549d25d44da2e197f773e757f155938
6
+ metadata.gz: 8a242dc0d21da39ec434a7e2f59b2d8ff3c57e427512909c792bce05de5a29a03fdc726484059f13dc0b931f4ec2be13e75dc06f0e06b8736d77c541fd6aeb7e
7
+ data.tar.gz: 34a6d942f8fc39392528d03e5d367d8d476c58da12424ba5a8a87b4cf749a85ca485dba6ee1741dd5b865a25aaa57d562c1b97d96f03af83a5485f4c142dcdeb
data/Gemfile CHANGED
@@ -6,6 +6,8 @@ gem 'coveralls', group: :test, require: false
6
6
 
7
7
  gemspec name: 'libis-format', development_group: :test
8
8
 
9
+ gem 'gem-release'
10
+
9
11
  group :development do
10
12
  gem 'byebug'
11
13
  gem 'debug'
data/data/types.yml CHANGED
@@ -377,7 +377,7 @@ PRESENTATION:
377
377
 
378
378
  OO_IMPRESS:
379
379
  NAME: OpenDocument Presentation (ODP)
380
- PUIID: fmt/138 fmt/292 fmt/293
380
+ PUID: fmt/138 fmt/292 fmt/293
381
381
  MIME: application/vnd.oasis.opendocument.presentation application/vnd.oasis.opendocument.presentation-template
382
382
  EXTENSIONS: odp otp
383
383
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'tty-prompt'
3
5
  require 'tty-config'
@@ -7,9 +9,7 @@ require 'libis/format/cli/format'
7
9
 
8
10
  module Libis
9
11
  module Format
10
-
11
12
  class CommandLine < Thor
12
-
13
13
  def self.exit_on_failure?
14
14
  true
15
15
  end
@@ -20,6 +20,5 @@ module Libis
20
20
  desc 'format', 'perform format identification on a given file or directory'
21
21
  subcommand 'format', Cli::Format
22
22
  end
23
-
24
23
  end
25
24
  end
@@ -1,10 +1,10 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'os'
3
4
  require 'libis-tools'
4
5
 
5
6
  module Libis
6
7
  module Format
7
-
8
8
  Config = ::Libis::Tools::Config
9
9
 
10
10
  Config[:converter_chain_max_level] = 8
@@ -15,10 +15,10 @@ module Libis
15
15
  Config[:ghostscript_cmd] = 'gs'
16
16
  Config[:droid_cmd] = '/opt/droid/droid.sh'
17
17
  Config[:droid_temp_path] = '/tmp'
18
- Config[:fido_cmd] = '/usr/local/bin/fido'
18
+ Config[:fido_cmd] = 'fido'
19
19
  Config[:fop_jar] = File.join(Libis::Format::TOOL_DIR, 'fop', 'build', 'fop.jar')
20
20
  Config[:ffmpeg_cmd] = 'ffmpeg'
21
- Config[:fido_formats] = [(File.join(Libis::Format::DATA_DIR, 'lias_formats.xml'))]
21
+ Config[:fido_formats] = [File.join(Libis::Format::DATA_DIR, 'lias_formats.xml')]
22
22
  Config[:pdf_tool] = File.join(Libis::Format::TOOL_DIR, 'PdfTool.jar')
23
23
  Config[:preflight_jar] = File.join(Libis::Format::TOOL_DIR, 'pdfbox', 'preflight-app-2.0.13.jar')
24
24
  Config[:wkhtmltopdf] = 'wkhtmltopdf'
@@ -27,21 +27,20 @@ module Libis
27
27
  Config[:raw_audio_convert_cmd] = 'sox -V1 %s -e signed -b 16 -t wav %s rate %d channels %d'
28
28
  Config[:watermark_font] = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf'
29
29
  Config[:timeouts] = {
30
- droid: 20 * 60,
31
- ffmpeg: 5 * 60,
32
- fido: 20 * 60,
33
- file_tool: 5 * 60,
34
- fop: 5 * 60,
35
- identification_tool: 5 * 60,
36
- office_to_pdf: 5 * 60,
37
- email2pdf: 5 * 60,
38
- pdf_copy: 5 * 60,
39
- pdf_merge: 5 * 60,
40
- pdf_optimizer: 5 * 60,
41
- pdf_split: 5 * 60,
42
- pdf_to_pdfa: 5 * 60,
43
- pdfa_validator: 5 * 60,
30
+ droid: 20 * 60,
31
+ ffmpeg: 5 * 60,
32
+ fido: 20 * 60,
33
+ file_tool: 5 * 60,
34
+ fop: 5 * 60,
35
+ identification_tool: 5 * 60,
36
+ office_to_pdf: 5 * 60,
37
+ email2pdf: 5 * 60,
38
+ pdf_copy: 5 * 60,
39
+ pdf_merge: 5 * 60,
40
+ pdf_optimizer: 5 * 60,
41
+ pdf_split: 5 * 60,
42
+ pdf_to_pdfa: 5 * 60,
43
+ pdfa_validator: 5 * 60
44
44
  }
45
-
46
45
  end
47
46
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  ### require 'tools/string'
4
4
  require 'tmpdir'
@@ -11,7 +11,6 @@ require_relative 'repository'
11
11
  module Libis
12
12
  module Format
13
13
  module Converter
14
-
15
14
  class Base
16
15
  include Libis::Tools::Logger
17
16
 
@@ -22,7 +21,7 @@ module Libis
22
21
  @flags = {}
23
22
  end
24
23
 
25
- def convert(source, target, format, opts = {})
24
+ def convert(source, _target, _format, opts = {})
26
25
  unless File.exist? source
27
26
  error "Cannot find file '#{source}'."
28
27
  return nil
@@ -32,35 +31,33 @@ module Libis
32
31
  end
33
32
 
34
33
  def self.input_types
35
- raise RuntimeError, 'Method #input_types needs to be overridden in converter'
34
+ raise 'Method #input_types needs to be overridden in converter'
36
35
  end
37
36
 
38
37
  def self.output_types(_format = nil)
39
- raise RuntimeError, 'Method #output_types needs to be overridden in converter'
38
+ raise 'Method #output_types needs to be overridden in converter'
40
39
  end
41
40
 
42
41
  def using_temp(target, &block)
43
42
  self.class.using_temp(target, &block)
44
43
  end
45
44
 
46
- def Base.using_temp(target)
45
+ def self.using_temp(target)
47
46
  tempfile = Tools::TempFile.name("convert-#{File.basename(target, '.*').gsub(/\s/, '_')}", File.extname(target))
48
47
  result = yield tempfile
49
48
  return nil unless result
49
+
50
50
  FileUtils.move result, target
51
51
  target
52
52
  end
53
53
 
54
- def Base.inherited( klass )
55
-
54
+ def self.inherited(klass) # rubocop:disable Lint/MissingSuper
56
55
  Repository.register klass
57
56
 
58
57
  class << self
59
-
60
58
  def conversions
61
- input_types.inject({}) do |hash, input_type|
59
+ input_types.each_with_object({}) do |input_type, hash|
62
60
  hash[input_type] = output_types
63
- hash
64
61
  end
65
62
  end
66
63
 
@@ -83,7 +80,7 @@ module Libis
83
80
  end
84
81
 
85
82
  def conversion?(input_type, output_type)
86
- conversions[input_type] and conversions[input_type].any? { |t| t == output_type }
83
+ conversions[input_type]&.any? { |t| t == output_type }
87
84
  end
88
85
 
89
86
  def output_for(input_type)
@@ -93,13 +90,9 @@ module Libis
93
90
  def extension?(extension)
94
91
  !TypeDatabase.ext_types(extension).first.nil?
95
92
  end
96
-
97
93
  end
98
-
99
94
  end
100
-
101
95
  end
102
-
103
96
  end
104
97
  end
105
98
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'fileutils'
4
4
  require 'deep_dive'
@@ -10,7 +10,6 @@ require 'libis/format/type_database'
10
10
  module Libis
11
11
  module Format
12
12
  module Converter
13
-
14
13
  class Chain
15
14
  include ::Libis::Tools::Logger
16
15
  include DeepDive
@@ -26,15 +25,16 @@ module Libis
26
25
  # @return [Array[Hash]]
27
26
  def append(converter)
28
27
  return [] unless converter
28
+
29
29
  valid_chain_nodes(converter).map do |node|
30
- self.ddup.add_chain_node(node)
30
+ ddup.add_chain_node(node)
31
31
  end.compact
32
32
  end
33
33
 
34
34
  def closed?
35
35
  !@converter_chain.empty? &&
36
- @converter_chain.first[:input].to_sym == @source_format &&
37
- @converter_chain.last[:output].to_sym == @target_format
36
+ @converter_chain.first[:input].to_sym == @source_format &&
37
+ @converter_chain.last[:output].to_sym == @target_format
38
38
  end
39
39
 
40
40
  def valid?
@@ -49,19 +49,14 @@ module Libis
49
49
  @converter_chain.size
50
50
  end
51
51
 
52
- alias_method :length, :size
52
+ alias length size
53
53
 
54
54
  def to_s
55
- "#{@source_format}->-#{@converter_chain.map do |node|
56
- "#{node[:converter].name.gsub(/^.*::/, '')}#{node[:operations].empty? ? '' :
57
- "(#{node[:operations].each do |operation|
58
- "#{operation[:method]}:#{operation[:argument]}"
59
- end.join(',')})"}->-#{node[:output]}"
60
- end.join('->-')}"
55
+ result = @source_format.to_s
56
+ result << @converter_chain.map { |node| node_to_s(node) }.join('->-')
61
57
  end
62
58
 
63
59
  def convert(src_file, target_file)
64
-
65
60
  unless valid?
66
61
  error 'Converter chain is not valid'
67
62
  return nil
@@ -74,15 +69,13 @@ module Libis
74
69
 
75
70
  # noinspection RubyParenthesesAroundConditionInspection
76
71
  conversion_success = @converter_chain.each_with_index do |node, i|
77
-
78
72
  target_type = node[:output]
79
73
  converter_class = node[:converter]
80
74
  converter = converter_class.new
81
75
 
82
-
83
- node[:operations].each do |operation|
76
+ node[:operations]&.each do |operation|
84
77
  converter.send operation[:method], operation[:argument]
85
- end if node[:operations]
78
+ end
86
79
 
87
80
  target = target_file
88
81
 
@@ -103,7 +96,6 @@ module Libis
103
96
  result[:commands] << r.merge(converter: converter_class.name)
104
97
 
105
98
  :success
106
-
107
99
  end
108
100
 
109
101
  result[:files] = [src_file] + xtra_files
@@ -113,16 +105,20 @@ module Libis
113
105
  end
114
106
 
115
107
  conversion_success == :failed ? nil : result
116
-
117
108
  end
118
109
 
119
110
  def valid_chain_nodes(converter)
120
- source_format = @converter_chain.last[:output] rescue @source_format
111
+ source_format = begin
112
+ @converter_chain.last[:output]
113
+ rescue StandardError
114
+ @source_format
115
+ end
121
116
  nodes = []
122
117
  if converter.input_types.include? source_format
123
118
  converter.output_types(source_format).each do |format|
124
- node = {converter: converter, input: source_format, output: format}
119
+ node = { converter:, input: source_format, output: format }
125
120
  next if node_exists?(node)
121
+
126
122
  nodes << node
127
123
  end
128
124
  end
@@ -137,6 +133,7 @@ module Libis
137
133
  return nil unless node[:output] && node[:converter].output_types(source_format).include?(node[:output])
138
134
  return nil unless node[:converter].input_types.include? source_format
139
135
  return nil if node_exists?(node)
136
+
140
137
  @converter_chain << node
141
138
  # debug "Chain: #{self}"
142
139
  self
@@ -145,15 +142,16 @@ module Libis
145
142
  def apply_operations
146
143
  temp_chain = @converter_chain.reverse.ddup
147
144
  applied = true
148
- operations = @operations && @operations.ddup || {}
145
+ operations = @operations&.ddup || {}
149
146
  while (operation = operations.shift)
150
147
  method = operation.first.to_s.to_sym
151
- applied &&= :found == temp_chain.each do |node|
148
+ applied &&= temp_chain.each do |node|
152
149
  next unless node[:converter].instance_methods.include?(method)
150
+
153
151
  node[:operations] ||= []
154
- node[:operations] << {method: method, argument: operation.last}
152
+ node[:operations] << { method:, argument: operation.last }
155
153
  break :found
156
- end
154
+ end == :found
157
155
  end
158
156
  if applied && operations.empty?
159
157
  @converter_chain = temp_chain.reverse
@@ -163,17 +161,27 @@ module Libis
163
161
  false
164
162
  end
165
163
 
166
-
167
164
  private
168
165
 
166
+ def node_to_s(node)
167
+ result = node[:converter].name.gsub(/^.*::/, '').to_s
168
+ unless node[:operations].empty?
169
+ result << '('
170
+ result << node[:operations].map do |operation|
171
+ "#{operation[:method]}:#{operation[:argument]}"
172
+ end.join(',')
173
+ result << ')'
174
+ end
175
+ result << '->-'
176
+ result << node[:output].to_s
177
+ end
178
+
169
179
  def node_exists?(node)
170
180
  @converter_chain.detect do |n|
171
181
  n[:converter] == node[:converter] && n[:input] == node[:input] && n[:output] == node[:output]
172
182
  end
173
183
  end
174
-
175
184
  end
176
-
177
185
  end
178
186
  end
179
187
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
4
 
@@ -9,20 +9,19 @@ require 'rexml/document'
9
9
  module Libis
10
10
  module Format
11
11
  module Converter
12
-
13
12
  class EmailConverter < Libis::Format::Converter::Base
14
-
15
13
  def self.input_types
16
- [ :MSG ]
14
+ [:MSG]
17
15
  end
18
16
 
19
17
  def self.output_types(format = nil)
20
18
  return [] unless input_types.include?(format)
21
- [ :PDF ]
19
+
20
+ [:PDF]
22
21
  end
23
22
 
24
23
  def email_convert(_)
25
- #force usage of this converter
24
+ # force usage of this converter
26
25
  end
27
26
 
28
27
  def convert(source, target, format, opts = {})
@@ -30,9 +29,7 @@ module Libis
30
29
 
31
30
  Format::Tool::MsgToPdf.run(source, target)
32
31
  end
33
-
34
32
  end
35
-
36
33
  end
37
34
  end
38
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nokogiri'
2
4
 
3
5
  require_relative 'base'
@@ -7,15 +9,14 @@ require 'libis/format/tool/fop_pdf'
7
9
  module Libis
8
10
  module Format
9
11
  module Converter
10
-
11
12
  class FopPdfConverter < Libis::Format::Converter::Base
12
-
13
13
  def self.input_types
14
14
  [:XML]
15
15
  end
16
16
 
17
17
  def self.output_types(format = nil)
18
- return [] unless input_types.include?(format) if format
18
+ return [] if format && !input_types.include?(format)
19
+
19
20
  [:PDF]
20
21
  end
21
22
 
@@ -30,11 +31,8 @@ module Libis
30
31
  FileUtils.mkpath(File.dirname(target))
31
32
 
32
33
  Libis::Format::Tool::FopPdf.run(source, target)
33
-
34
34
  end
35
-
36
35
  end
37
-
38
36
  end
39
37
  end
40
38
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
4
  require 'libis/format/identifier'
@@ -13,26 +13,26 @@ MiniMagick.configure do |config|
13
13
  config.validate_on_create = false
14
14
  config.validate_on_write = false
15
15
  config.whiny = false
16
+ config.tmpdir = Libis::Format::Config[:tempdir] || Dir.tmpdir
16
17
  end
17
18
 
18
19
  module Libis
19
20
  module Format
20
21
  module Converter
21
-
22
22
  # noinspection RubyTooManyInstanceVariablesInspection
23
23
  class ImageConverter < Libis::Format::Converter::Base
24
-
25
24
  def self.input_types
26
- [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
25
+ %i[TIFF JPG PNG BMP GIF PDF JP2]
27
26
  end
28
27
 
29
28
  def self.output_types(format = nil)
30
29
  return [] unless input_types.include?(format)
31
- [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
30
+
31
+ %i[TIFF JPG PNG BMP GIF PDF JP2]
32
32
  end
33
33
 
34
34
  def self.multipage?(format)
35
- [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM].include?(format)
35
+ %i[PDF TIFF GIF PBM PGM PPM].include?(format)
36
36
  end
37
37
 
38
38
  def initialize
@@ -41,15 +41,15 @@ module Libis
41
41
  end
42
42
 
43
43
  def image_convert(_)
44
- #force usage of this converter
44
+ # force usage of this converter
45
45
  end
46
46
 
47
- def quiet(v)
48
- @quiet = !!v
47
+ def quiet(value)
48
+ @quiet = !!value
49
49
  end
50
50
 
51
- def page(nr)
52
- @page = nr
51
+ def page(number)
52
+ @page = number
53
53
  end
54
54
 
55
55
  def scale(percent)
@@ -122,33 +122,33 @@ module Libis
122
122
  @wm_gap = ((options[:gap] || 0.2).to_f * 100).to_i
123
123
  rotation = 360 - (options[:rotation] || 30).to_i
124
124
  @wm_image = MiniMagick::Image.new(options[:file]) if options[:file]
125
- unless @wm_image && @wm_image.valid?
126
- image = options[:file] || (Dir::Tmpname.create(%w(wm_image .png)) {|_|})
127
- # noinspection RubyResolve
128
- MiniMagick::Tool::Convert.new do |convert|
129
- # noinspection RubyLiteralArrayInspection
130
- convert.quiet
131
- convert.background 'transparent'
132
- convert.size('2000x2000')
133
- convert.gravity 'Center'
134
- convert.font('Helvetica').fill('black').pointsize(72) #.stroke('black').strokewidth(1)
135
- convert << "label:#{text}"
136
- convert.rotate rotation
137
- convert.trim.repage.+
138
- convert << image
139
- end
140
- if options[:file]
141
- @wm_image = MiniMagick::Image.new(image)
142
- else
143
- @wm_image = MiniMagick::Image.open(image)
144
- File.delete(image)
145
- end
146
- # noinspection RubyResolve
147
- unless @wm_image.valid?
148
- error "Problem creating watermark image '#{image}'."
149
- @wm_image = nil
150
- end
125
+ return if @wm_image&.valid?
126
+
127
+ image = options[:file] || (Dir::Tmpname.create(%w[wm_image .png]) { |_| })
128
+ # noinspection RubyResolve
129
+ MiniMagick::Tool::Convert.new do |convert|
130
+ # noinspection RubyLiteralArrayInspection
131
+ convert.quiet
132
+ convert.background 'transparent'
133
+ convert.size('2000x2000')
134
+ convert.gravity 'Center'
135
+ convert.font('Helvetica').fill('black').pointsize(72) # .stroke('black').strokewidth(1)
136
+ convert << "label:#{text}"
137
+ convert.rotate rotation
138
+ convert.trim.repage.+ # rubocop:disable Lint/Void
139
+ convert << image
140
+ end
141
+ if options[:file]
142
+ @wm_image = MiniMagick::Image.new(image)
143
+ else
144
+ @wm_image = MiniMagick::Image.open(image)
145
+ File.delete(image)
151
146
  end
147
+ # noinspection RubyResolve
148
+ return if @wm_image.valid?
149
+
150
+ error "Problem creating watermark image '#{image}'."
151
+ @wm_image = nil
152
152
  end
153
153
 
154
154
  def convert(source, target, format, opts = {})
@@ -161,34 +161,33 @@ module Libis
161
161
  assemble_and_convert(source, target, format)
162
162
 
163
163
  elsif File.directory?(source)
164
- source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
164
+ source_list = Dir[File.join(source, '**', '*')].reject { |p| File.directory? p }
165
165
 
166
166
  assemble_and_convert(source_list, target, format)
167
167
 
168
168
  else
169
169
 
170
- image = MiniMagick::Image.open(source) { |b| b.quiet }
170
+ image = MiniMagick::Image.open(source) { |b| b.quiet } # rubocop:disable Style/SymbolProc
171
171
 
172
172
  if image.pages.size > 1
173
173
  if @page
174
174
  convert_image(image.pages[@page].path, target, format)
175
175
  else
176
176
  # noinspection RubyBlockToMethodReference
177
- assemble_and_convert(image.pages.map {|page| page.path}, target, format)
177
+ assemble_and_convert(image.pages.map(&:path), target, format)
178
178
  end
179
179
  else
180
180
  convert_image(source, target, format)
181
181
  end
182
182
  end
183
-
184
- {
183
+
184
+ {
185
185
  files: [target],
186
186
  converter: self.class.name
187
187
  }
188
188
  end
189
189
 
190
190
  def assemble_and_convert(sources, target, format)
191
-
192
191
  warn 'Received multiple images as input and single page format as target.' unless self.class.multipage?(format)
193
192
  converted_pages = sources.inject([]) do |list, path|
194
193
  # noinspection RubyArgCount
@@ -198,7 +197,7 @@ module Libis
198
197
  end
199
198
  MiniMagick::Tool::Convert.new do |b|
200
199
  b.append unless self.class.multipage?(format)
201
- converted_pages.each {|page| b << page.path}
200
+ converted_pages.each { |page| b << page.path }
202
201
  b << target
203
202
  end
204
203
  converted_pages.each do |temp_file|
@@ -210,17 +209,16 @@ module Libis
210
209
  protected
211
210
 
212
211
  def convert_image(source, target, format)
213
-
214
212
  image_info = nil
215
- image_info = MiniMagick::Image::Info.new(source) {|b| b.quiet} if @wm_image
213
+ image_info = MiniMagick::Image::Info.new(source) { |b| b.quiet } if @wm_image # rubocop:disable Style/SymbolProc
216
214
 
217
215
  MiniMagick::Tool::Convert.new do |convert|
218
216
  convert.quiet if @quiet
219
217
  if @wm_image
220
218
  convert << @wm_image.path
221
- convert.bordercolor('transparent').border("#{@wm_gap}%") if @wm_gap > 0
219
+ convert.bordercolor('transparent').border("#{@wm_gap}%") if @wm_gap.positive?
222
220
  convert.filter('Lagrange')
223
- convert.resize("#{image_info['width'] / @wm_tiles}x#{image_info['height'] / @wm_tiles}") if @wm_tiles > 0
221
+ convert.resize("#{image_info['width'] / @wm_tiles}x#{image_info['height'] / @wm_tiles}") if @wm_tiles.positive?
224
222
  convert.resize("#{@wm_resize}%") if @wm_resize
225
223
  convert.write('mpr:watermark').delete.+
226
224
  end
@@ -229,7 +227,7 @@ module Libis
229
227
  convert << source
230
228
  convert.flatten if @options[:flatten].nil? && format == :JPG
231
229
  if @wm_image
232
- if @wm_tiles >= 0 and @wm_tiles <= 1
230
+ if (@wm_tiles >= 0) && (@wm_tiles <= 1)
233
231
  convert << 'mpr:watermark'
234
232
  else
235
233
  convert.stack do |stack|
@@ -242,15 +240,13 @@ module Libis
242
240
  convert.compose(@wm_composition).gravity(@wm_gravity).define("compose:args=#{@wm_opacity}%").composite
243
241
  end
244
242
 
245
- @flags.each {|f, v| v.is_a?(TrueClass) ? convert.send(f).+ : convert.send(f)}
246
- if @delete_date
247
- convert << '+set' << 'modify-date' << '+set' << 'create-date'
248
- end
243
+ @flags.each { |f, v| v.is_a?(TrueClass) ? convert.send(f).+ : convert.send(f) }
244
+ convert << '+set' << 'modify-date' << '+set' << 'create-date' if @delete_date
249
245
 
250
246
  colorspace = @options.delete(:colorspace) || 'sRGB'
251
247
  unless @options.empty?
252
248
  convert.colorspace('RGB')
253
- @options.each {|o, v| convert.send(o, v)}
249
+ @options.each { |o, v| convert.send(o, v) }
254
250
  end
255
251
  convert.colorspace(colorspace)
256
252
  convert.profile @profile if @profile
@@ -262,11 +258,8 @@ module Libis
262
258
  end
263
259
 
264
260
  target
265
-
266
261
  end
267
-
268
262
  end
269
-
270
263
  end
271
264
  end
272
- end
265
+ end