libis-format 1.3.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +20 -0
  4. data/.travis.yml +70 -0
  5. data/Gemfile +0 -12
  6. data/README.md +2 -2
  7. data/Rakefile +8 -0
  8. data/base/Dockerfile +35 -0
  9. data/base/Dockerfile.alpine +20 -0
  10. data/base/Dockerfile.rvm +56 -0
  11. data/base/rework_path +20 -0
  12. data/bin/{pdf_tool → pdf_copy} +2 -3
  13. data/data/PDFA_def.ps +3 -3
  14. data/data/eciRGB_v2.icc +0 -0
  15. data/data/types.yml +4 -17
  16. data/docker_cfg.yml +1 -0
  17. data/lib/libis/format/cli/convert.rb +4 -4
  18. data/lib/libis/format/cli/prompt_helper.rb +24 -32
  19. data/lib/libis/format/command_line.rb +3 -2
  20. data/lib/libis/format/config.rb +23 -19
  21. data/lib/libis/format/converter/audio_converter.rb +31 -56
  22. data/lib/libis/format/converter/base.rb +36 -16
  23. data/lib/libis/format/converter/chain.rb +32 -52
  24. data/lib/libis/format/converter/fop_pdf_converter.rb +8 -4
  25. data/lib/libis/format/converter/image_assembler.rb +82 -0
  26. data/lib/libis/format/converter/image_converter.rb +45 -250
  27. data/lib/libis/format/converter/image_splitter.rb +80 -0
  28. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  29. data/lib/libis/format/converter/jp2_converter.rb +38 -36
  30. data/lib/libis/format/converter/office_converter.rb +28 -22
  31. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  32. data/lib/libis/format/converter/pdf_converter.rb +52 -200
  33. data/lib/libis/format/converter/pdf_optimizer.rb +70 -0
  34. data/lib/libis/format/converter/pdf_splitter.rb +65 -0
  35. data/lib/libis/format/converter/pdf_watermarker.rb +110 -0
  36. data/lib/libis/format/converter/repository.rb +13 -7
  37. data/lib/libis/format/converter/spreadsheet_converter.rb +16 -10
  38. data/lib/libis/format/converter/video_converter.rb +58 -47
  39. data/lib/libis/format/converter/xslt_converter.rb +11 -13
  40. data/lib/libis/format/converter.rb +1 -1
  41. data/lib/libis/format/identifier.rb +46 -44
  42. data/lib/libis/format/info.rb +27 -0
  43. data/lib/libis/format/library.rb +147 -0
  44. data/lib/libis/format/tool/droid.rb +30 -29
  45. data/lib/libis/format/tool/extension_identification.rb +26 -24
  46. data/lib/libis/format/tool/{ff_mpeg.rb → ffmpeg.rb} +10 -17
  47. data/lib/libis/format/tool/fido.rb +27 -22
  48. data/lib/libis/format/tool/file_tool.rb +24 -11
  49. data/lib/libis/format/tool/fop_pdf.rb +14 -25
  50. data/lib/libis/format/tool/identification_tool.rb +40 -38
  51. data/lib/libis/format/tool/office_to_pdf.rb +18 -30
  52. data/lib/libis/format/tool/pdf_copy.rb +47 -0
  53. data/lib/libis/format/tool/pdf_merge.rb +19 -25
  54. data/lib/libis/format/tool/pdf_optimizer.rb +19 -22
  55. data/lib/libis/format/tool/pdf_split.rb +33 -6
  56. data/lib/libis/format/tool/pdf_to_pdfa.rb +31 -45
  57. data/lib/libis/format/tool/pdfa_validator.rb +30 -24
  58. data/lib/libis/format/tool/spreadsheet_to_ods.rb +18 -29
  59. data/lib/libis/format/tool.rb +3 -4
  60. data/lib/libis/format/version.rb +1 -3
  61. data/lib/libis/format/yaml_loader.rb +71 -0
  62. data/lib/libis/format.rb +7 -5
  63. data/lib/libis-format.rb +0 -2
  64. data/libis-format.gemspec +18 -24
  65. data/tools/PdfTool.jar +0 -0
  66. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
  67. data/tools/pdfbox/{preflight-app-3.0.3.jar → preflight-app-2.0.13.jar} +0 -0
  68. metadata +86 -128
  69. data/data/AdobeRGB1998.icc +0 -0
  70. data/lib/libis/format/converter/email_converter.rb +0 -35
  71. data/lib/libis/format/tool/msg_to_pdf.rb +0 -270
  72. data/lib/libis/format/tool/pdf_tool.rb +0 -52
  73. data/lib/libis/format/type_database.rb +0 -156
  74. data/lib/libis/format/type_database_impl.rb +0 -153
  75. data/tools/pdf2pdfa +0 -395
  76. data/tools/pdfbox/pdfbox-app-3.0.3.jar +0 -0
  77. /data/bin/{droid_tool → droid} +0 -0
  78. /data/bin/{fido_tool → fido} +0 -0
@@ -1,143 +1,52 @@
1
- # frozen_string_literal: true
1
+ # encoding: utf-8
2
2
 
3
3
  require_relative 'base'
4
4
 
5
5
  require 'libis/tools/extend/hash'
6
- require 'libis/format/tool/pdf_tool'
6
+ require 'libis/format/tool/pdf_copy'
7
7
  require 'libis/format/tool/pdf_to_pdfa'
8
- require 'libis/format/tool/pdfa_validator'
9
8
  require 'libis/format/tool/pdf_optimizer'
10
9
 
11
10
  module Libis
12
11
  module Format
13
12
  module Converter
13
+
14
+ # noinspection DuplicatedCode
14
15
  class PdfConverter < Libis::Format::Converter::Base
16
+
15
17
  def self.input_types
16
18
  [:PDF]
17
19
  end
18
20
 
19
21
  def self.output_types(format = nil)
20
- return [] unless input_types.include?(format)
21
-
22
- %i[PDF PDFA]
23
- end
24
-
25
- def pdf_convert(_)
26
- # force usage of this converter
27
- end
28
-
29
- # Set metadata for Pdf file
30
- #
31
- # valid metadata keys are):
32
- # - title
33
- # - author
34
- # - creator
35
- # - keywords
36
- # - subject
37
- #
38
- # @param [Hash] values list of metadata values to set
39
- def metadata(values = {})
40
- values.key_strings_to_symbols!
41
- values.each do |k, v|
42
- next unless %i[title author creator keywords subject].include?(k)
43
- (@options[:metadata] ||= {})[k] = v
44
- end
22
+ return [] unless input_types.include?(format) if format
23
+ [:PDF, :PDFA]
45
24
  end
46
25
 
47
- # Select a partial list of pages
48
- # @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
49
- def range(selection)
50
- @options[:select] = {range: [selection].flatten.compact.join(',')}
26
+ def title(v)
27
+ @options[:title] = v.blank? ? nil : v
51
28
  end
52
29
 
53
- # Create or use a watermark image.
54
- #
55
- # The watermark options are (use symbols):
56
- # - text: text to create a watermark from
57
- # - file: watermark image to use
58
- # - image: same as above
59
- # - rotation: rotation of the watermark text (in degrees; integer number)
60
- # - size: font size of the watermark text
61
- # - opacity: opacity of the watermark (fraction 0.0 - 1.0)
62
- # - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch).
63
- # Fractions are percentage of widht/height.
64
- # If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
65
- # file will be created or overwritten with a newly created watermark image.
66
- #
67
- # The created watermark file will be a PNG image with transparent background containing the supplied text
68
- # slanted by 30 degrees counter-clockwise.
69
- #
70
- # @param [Hash] options Hash of options for watermark creation.
71
- def watermark(options = {})
72
- options.key_strings_to_symbols!
73
- if options[:file] || options[:image]
74
- watermark_image(options)
75
- elsif options[:text]
76
- watermark_text(options)
77
- elsif options[:banner]
78
- watermark_banner(options)
79
- end
30
+ def author(v)
31
+ @options[:author] = v.blank? ? nil : v
80
32
  end
81
33
 
82
- def watermark_image(options = {})
83
- options.key_strings_to_symbols!
84
- @options[:watermark] = {command: 'image'}
85
- @options[:watermark][:data] = options[:file] || options[:image]
86
- @options[:watermark][:opacity] = options[:opacity] || '0.3'
87
-
34
+ def creator(v)
35
+ @options[:creator] = v.blank? ? nil : v
88
36
  end
89
37
 
90
- def watermark_text(options = {})
91
- options.key_strings_to_symbols!
92
- @options[:watermark] = {command: 'text'}
93
- @options[:watermark][:data] = (options[:text] || '© LIBIS').split('\n')
94
- @options[:watermark][:rotation] = options[:rotation] if options[:rotation]
95
- @options[:watermark][:size] = options[:size] if options[:size]
96
- @options[:watermark][:gap] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
97
- @options[:watermark][:padding] = options[:gap] if options[:gap].to_s =~ /^\s*(0+\.\d+|1\.0+)\s*$/
98
- @options[:watermark][:padding] = options[:padding] if options[:padding]
99
- @options[:watermark][:opacity] = options[:opacity] || '0.3'
38
+ def keywords(v)
39
+ @options[:keywords] = v.blank? ? nil : v
100
40
  end
101
41
 
102
- # Create a vertical banner to the right side of each page
103
- #
104
- # The banner options are:
105
- # - banner: text to put in the banner
106
- # - add_filename: append filename to the text (use any value to enable)
107
- # - fontsize: size of the font (in points)
108
- # - width: width of the banner
109
- # - (background|text)_color_(red|green|blue): color components of background and text
110
- def watermark_banner(options = {})
111
- options.key_strings_to_symbols!
112
- @options[:watermark] = {command: 'banner'}
113
- @options[:watermark][:data] = (options[:banner] || '© LIBIS')
114
- @options[:watermark][:add_filename] = !!options[:add_filename]
115
- @options[:watermark][:size] = options[:fontsize] if options[:fontsize]
116
- @options[:watermark][:width] = options[:width] if options[:width]
117
- @options[:watermark][:background_red] = options[:background_color_red] if options[:background_color_red]
118
- @options[:watermark][:background_green] = options[:background_color_green] if options[:background_color_green]
119
- @options[:watermark][:background_blue] = options[:background_color_blue] if options[:background_color_blue]
120
- @options[:watermark][:text_red] = options[:text_color_red] if options[:text_color_red]
121
- @options[:watermark][:text_green] = options[:text_color_green] if options[:text_color_green]
122
- @options[:watermark][:text_blue] = options[:text_color_blue] if options[:text_color_blue]
42
+ def subject(v)
43
+ @options[:subject] = v.blank? ? nil : v
123
44
  end
124
45
 
125
- # Optimize the PDF
126
- #
127
- # This reduces the graphics quality to a level in order to limit file size. This option relies on the
128
- # presence of ghostscript and takes one argument: the quality level. It should be one of:
129
- #
130
- # - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
131
- # - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
132
- # - 2 : good quality (Acrobat Distiller 'Default' equivalent)
133
- # - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
134
- # - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
135
- #
136
- # Note that the optimization is intended to be used with PDF's containing high-resolution images.
137
- #
138
- # @param [Integer] setting quality setting. [0-4]
139
- def optimize(setting = 1)
140
- @options[:optimize] = %w[screen ebook default printer prepress][setting] if (0..4).include?(setting)
46
+ # Select a partial list of pages
47
+ # @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
48
+ def range(selection)
49
+ @options[:ranges] = selection.blank? ? nil : selection
141
50
  end
142
51
 
143
52
  def convert(source, target, format, opts = {})
@@ -147,122 +56,65 @@ module Libis
147
56
 
148
57
  unless @options.empty?
149
58
  result = convert_pdf(source, target)
59
+ return nil unless result
150
60
  source = result
151
61
  end
152
62
 
153
- if source && (quality = @options.delete(:optimize))
154
- result = optimize_pdf(source, target, quality)
155
- source = result
156
- end
157
-
158
- if source && (format == :PDFA)
63
+ if format == :PDFA and source
159
64
  result = pdf_to_pdfa(source, target)
160
65
  end
161
66
 
162
- {
163
- files: [result],
164
- converter: self.class.name
165
- }
166
- end
167
-
168
- protected
67
+ result
169
68
 
170
- def optimize_pdf(source, target, quality)
171
- using_temp(target) do |tmpname|
172
- result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
173
- unless result[:err].empty?
174
- error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
175
- return nil
176
- end
177
- tmpname
178
- end
179
69
  end
180
70
 
181
- def convert_pdf(source, target)
182
- result = source
183
- result = add_watermark(result, target, @options[:watermark]) if @options[:watermark]
184
- result = add_metadata(result, target, @options[:metadata]) if @options[:metadata]
185
- result = select_range(result, target, @options[:select]) if @options[:select]
186
- return result
187
- end
188
-
189
- def options_to_args(options)
190
- options.map do |k, v|
191
- key = "--#{k.to_s.tr_s('_', '-')}"
192
- value = v
193
- case value
194
- when TrueClass
195
- value = nil
196
- when FalseClass
197
- value = key = nil
198
- when Array
199
- value = value.map(&:to_s)
200
- else
201
- value = v.to_s
202
- end
203
- [key, value]
204
- end.flatten.compact
205
- end
206
-
207
- def add_watermark(source, target, options)
208
- command = options.delete(:command)
209
- data = [options.delete(:data)].flatten.compact
210
- args = data + options_to_args(options)
211
-
212
- using_temp(target) do |tmpname|
213
- result = Libis::Format::Tool::PdfTool.run(['watermark', command], source, tmpname, *args)
214
- unless result[:err].empty?
215
- error("Pdf watermarking encountered errors:\n%s", result[:err].join(join("\n")))
216
- return nil
217
- end
218
- tmpname
219
- end
220
- end
71
+ OPTIONS_TABLE = {
72
+ title: 'md_title',
73
+ author: 'md_author',
74
+ creator: 'md_creator',
75
+ keywords: 'md_keywords',
76
+ subject: 'md_subject'
77
+ }
221
78
 
222
- def add_metadata(source, target, options)
223
- args = options_to_args(options)
79
+ def convert_pdf(source, target)
224
80
 
225
81
  using_temp(target) do |tmpname|
226
- result = Libis::Format::Tool::PdfTool.run('metadata', source, tmpname, *args)
82
+ result = Libis::Format::Tool::PdfCopy.run(
83
+ source, tmpname,
84
+ @options.map {|k, v|
85
+ if v.nil?
86
+ nil
87
+ else
88
+ k = OPTIONS_TABLE[k] || k
89
+ ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
90
+ end}.compact.flatten
91
+ )
227
92
  unless result[:err].empty?
228
- error("Pdf metadata encountered errors:\n%s", result[:err].join(join("\n")))
229
- return nil
93
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
94
+ next nil
230
95
  end
231
96
  tmpname
232
97
  end
233
- end
234
98
 
235
- def select_range(source, target, options)
236
- args = options_to_args(options)
237
-
238
- using_temp(target) do |tmpname|
239
- result = Libis::Format::Tool::PdfTool.run('select', source, tmpname, *args)
240
- unless result[:err].empty?
241
- error("Pdf select encountered errors:\n%s", result[:err].join(join("\n")))
242
- return nil
243
- end
244
- tmpname
245
- end
246
99
  end
247
100
 
248
101
  def pdf_to_pdfa(source, target)
102
+
249
103
  using_temp(target) do |tmpname|
250
104
  result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
251
-
252
- unless result[:status].zero?
253
- error("Pdf/A conversion encountered errors:\n%s", (result[:out] + result[:err]).join("\n"))
254
- return nil
105
+ if result[:status] != 0
106
+ error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
107
+ next nil
255
108
  else
256
- r = Libis::Format::Tool::PdfaValidator.run tmpname
257
- if r[:status] != 0
258
- error "Pdf/A file failed to validate with following errors:\n%s", (r[:err] || r[:out] || []).join("\n")
259
- return nil
260
- end
109
+ warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
261
110
  end
262
111
  tmpname
263
112
  end
113
+
264
114
  end
115
+
265
116
  end
117
+
266
118
  end
267
119
  end
268
120
  end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/tools/extend/hash'
6
+ require 'libis/format/tool/pdf_copy'
7
+ require 'libis/format/tool/pdf_to_pdfa'
8
+ require 'libis/format/tool/pdf_optimizer'
9
+
10
+ module Libis
11
+ module Format
12
+ module Converter
13
+
14
+ class PdfOptimizer < Libis::Format::Converter::Base
15
+
16
+ def self.input_types
17
+ [:PDF]
18
+ end
19
+
20
+ def self.output_types(format = nil)
21
+ return [] unless input_types.include?(format) if format
22
+ [:PDF]
23
+ end
24
+
25
+ def pdf_optimize(_)
26
+ #force usage of this converter
27
+ end
28
+
29
+ # Optimize the PDF
30
+ #
31
+ # This reduces the graphics quality to a level in order to limit file size. This option relies on the
32
+ # presence of ghostscript and takes one argument: the quality level. It should be one of:
33
+ #
34
+ # - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
35
+ # - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
36
+ # - 2 : good quality
37
+ # - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
38
+ # - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
39
+ #
40
+ # Note that the optimization is intended to be used with PDF's containing high-resolution images.
41
+ #
42
+ # @param [Integer] setting quality setting. [0-4]
43
+ def quality(setting = 1)
44
+ @quality = %w(screen ebook default printer prepress)[setting] if (0..4) === setting
45
+ end
46
+
47
+ def convert(source, target, format, opts = {})
48
+ super
49
+
50
+ optimize_pdf(source, target, @quality || 'ebook')
51
+
52
+ end
53
+
54
+ def optimize_pdf(source, target, quality)
55
+
56
+ using_temp(target) do |tmpname|
57
+ result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
58
+ unless result[:status] == 0
59
+ error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
60
+ next nil
61
+ end
62
+ tmpname
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_split'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ # noinspection DuplicatedCode
12
+ class PdfSplitter < Libis::Format::Converter::Base
13
+
14
+ def self.input_types
15
+ [:PDF]
16
+ end
17
+
18
+ def self.output_types(format = nil)
19
+ return [] unless input_types.include?(format) if format
20
+ [:PDF]
21
+ end
22
+
23
+ def pdf_split(_)
24
+ #force usage of this converter
25
+ end
26
+
27
+ def self.category
28
+ :splitter
29
+ end
30
+
31
+ # Split at given page. If omitted or nil, the source PDF will be split at every page
32
+ def page(v)
33
+ @page = v unless v.blank
34
+ end
35
+
36
+ def convert(source, target, format, opts = {})
37
+ super
38
+
39
+ result = split(source, target)
40
+ return nil unless result
41
+
42
+ result
43
+ end
44
+
45
+ private
46
+
47
+ def split(source, target)
48
+
49
+ options = @page ? ['--page', @page] : ['--every_page']
50
+ using_temp(target) do |tmpname|
51
+ result = Libis::Format::Tool::PdfSplit.run(source, tmpname, *options)
52
+ unless result[:err].empty?
53
+ error("Pdf split encountered errors:\n%s", result[:err].join(join("\n")))
54
+ next nil
55
+ end
56
+ tmpname
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,110 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/tools/extend/hash'
6
+ require 'libis/format/tool/pdf_copy'
7
+ require 'libis/format/tool/pdf_to_pdfa'
8
+ require 'libis/format/tool/pdf_optimizer'
9
+
10
+ module Libis
11
+ module Format
12
+ module Converter
13
+
14
+ class PdfWatermarker < Libis::Format::Converter::Base
15
+
16
+ def self.input_types
17
+ [:PDF]
18
+ end
19
+
20
+ def self.output_types(format = nil)
21
+ return [] unless input_types.include?(format) if format
22
+ [:PDF]
23
+ end
24
+
25
+ def pdf_watermark(_)
26
+ #force usage of this converter
27
+ end
28
+
29
+ def initialize
30
+ super
31
+ @options[:text] = '© LIBIS'
32
+ @options[:opacity] = '0.3'
33
+ end
34
+
35
+ def file(v)
36
+ @options[:file] = v.blank? ? nil : v
37
+ end
38
+
39
+ def text(v)
40
+ @options[:text] = v
41
+ end
42
+
43
+ def rotation(v)
44
+ @options[:rotation] = v unless v.blank?
45
+ end
46
+
47
+ def size(v)
48
+ @options[:size] = v unless v.blank?
49
+ end
50
+
51
+ def opacity(v)
52
+ @options[:opacity] = v unless v.blank?
53
+ end
54
+
55
+ def gap_size(v)
56
+ @options[:gap_size] = v
57
+ end
58
+
59
+ def gap_ratio(v)
60
+ @options[:gap_ratio] = v
61
+ end
62
+
63
+ def convert(source, target, format, opts = {})
64
+ super
65
+
66
+ result = convert_pdf(source, target)
67
+ return nil unless result
68
+
69
+ result
70
+
71
+ end
72
+
73
+ OPTIONS_TABLE = {
74
+ file: 'wm_image',
75
+ text: 'wm_text',
76
+ rotation: 'wm_text_rotation',
77
+ size: 'wm_font_size',
78
+ opacity: 'wm_opacity',
79
+ gap_size: 'wm_gap_size',
80
+ gap_ratio: 'wm_gap_ratio'
81
+ }
82
+ # noinspection DuplicatedCode
83
+ def convert_pdf(source, target)
84
+
85
+ using_temp(target) do |tmpname|
86
+ result = Libis::Format::Tool::PdfCopy.run(
87
+ source, tmpname,
88
+ @options.map {|k, v|
89
+ if v.nil?
90
+ nil
91
+ else
92
+ v = v.split('\n') unless v.blank? if k == :text
93
+ k = OPTIONS_TABLE[k] || k
94
+ ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
95
+ end}.compact.flatten
96
+ )
97
+ unless result[:err].empty?
98
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
99
+ next nil
100
+ end
101
+ tmpname
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+ end
110
+ end
@@ -1,5 +1,6 @@
1
- # frozen_string_literal: true
1
+ # coding: utf-8
2
2
 
3
+ require 'set'
3
4
  require 'singleton'
4
5
 
5
6
  require 'libis/tools/logger'
@@ -10,6 +11,7 @@ require_relative 'chain'
10
11
  module Libis
11
12
  module Format
12
13
  module Converter
14
+
13
15
  class Repository
14
16
  include Singleton
15
17
  include ::Libis::Tools::Logger
@@ -22,15 +24,15 @@ module Libis
22
24
  @converters_glob = File.join(File.dirname(__FILE__), '*_converter.rb')
23
25
  end
24
26
 
25
- def self.register(converter_class)
27
+ def Repository.register(converter_class)
26
28
  instance.converters.add? converter_class
27
29
  end
28
30
 
29
- def self.get_converters # rubocop:disable Naming/AccessorMethodName
31
+ def Repository.get_converters
30
32
  instance.get_converters
31
33
  end
32
34
 
33
- def get_converters # rubocop:disable Naming/AccessorMethodName
35
+ def get_converters
34
36
  if converters.empty?
35
37
  Dir.glob(converters_glob).each do |filename|
36
38
  # noinspection RubyResolve
@@ -40,12 +42,12 @@ module Libis
40
42
  converters
41
43
  end
42
44
 
43
- def self.get_converter_chain(src_type, tgt_type, operations = {})
45
+ def Repository.get_converter_chain(src_type, tgt_type, operations = {})
44
46
  instance.get_converter_chain src_type, tgt_type, operations
45
47
  end
46
48
 
47
49
  def get_converter_chain(src_type, tgt_type, operations = {})
48
- msg = "conversion from #{src_type} to #{tgt_type}"
50
+ msg = "conversion from #{src_type.to_s} to #{tgt_type.to_s}"
49
51
  chain_list = find_chains src_type, tgt_type, operations
50
52
  # if chain_list.length > 1
51
53
  # warn "Found more than one conversion chain for #{msg}. Picking the first one."
@@ -68,6 +70,7 @@ module Libis
68
70
  end
69
71
 
70
72
  def build_chains(chain)
73
+
71
74
  found = []
72
75
  chains = [chain]
73
76
 
@@ -78,15 +81,18 @@ module Libis
78
81
  new_chains += chains.map { |c| c.append(converter) }.flatten
79
82
  end
80
83
 
81
- found = new_chains.select(&:valid?)
84
+ found = new_chains.select { |c| c.valid?}
82
85
  return found unless found.empty?
83
86
 
84
87
  chains = new_chains
85
88
  end
86
89
 
87
90
  found
91
+
88
92
  end
93
+
89
94
  end
95
+
90
96
  end
91
97
  end
92
98
  end
@@ -1,38 +1,44 @@
1
- # frozen_string_literal: true
1
+ # encoding: utf-8
2
2
 
3
3
  require_relative 'base'
4
4
 
5
5
  require 'libis/format/tool/spreadsheet_to_ods'
6
- require 'libis/format/type_database'
6
+ require 'libis/format/library'
7
7
 
8
8
  module Libis
9
9
  module Format
10
10
  module Converter
11
+
11
12
  class SpreadsheetConverter < Libis::Format::Converter::Base
13
+
12
14
  def self.input_types
13
- %i[
14
- MSXLS
15
- MSXLSX
16
- OO_CALC
15
+ [
16
+ :MSXLS,
17
+ :MSXLSX,
18
+ :OO_CALC
17
19
  ]
18
20
  end
19
21
 
20
22
  def self.output_types(format = nil)
21
- return [] unless input_types.include?(format)
22
-
23
+ return [] unless input_types.include?(format) if format
23
24
  [:OO_CALC]
24
25
  end
25
26
 
26
27
  def spreadsheet_convert(_)
27
- # force usage of this converter
28
+ #force usage of this converter
28
29
  end
29
30
 
30
31
  def convert(source, target, format, opts = {})
31
32
  super
32
33
 
33
- Format::Tool::SpreadsheetToOds.run(source, target)
34
+ return nil unless Format::Tool::SpreadsheetToOds.run(source, target)
35
+
36
+ target
37
+
34
38
  end
39
+
35
40
  end
41
+
36
42
  end
37
43
  end
38
44
  end