Class: Pdf::Compressor
- Inherits:
-
BaseService
- Object
- BaseService
- Pdf::Compressor
- Defined in:
- app/services/pdf/compressor.rb
Overview
Service object: compressor.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- PDF_SETTINGS =
Pdf settings.
%w[/screen /ebook /printer /prepress /default].freeze
- COMPATIBILITY_LEVELS =
Compatibility levels.
%w[1.2 1.3 1.4 1.5 1.6 1.7].freeze
Instance Attribute Summary collapse
-
#compatibility_level ⇒ Object
readonly
Returns the value of attribute compatibility_level.
-
#input_blob ⇒ Object
readonly
Returns the value of attribute input_blob.
-
#input_path ⇒ Object
readonly
Returns the value of attribute input_path.
-
#output_blob ⇒ Object
readonly
Returns the value of attribute output_blob.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#pdf_setting ⇒ Object
readonly
Returns the value of attribute pdf_setting.
Attributes inherited from BaseService
Instance Method Summary collapse
- #compress ⇒ Object
-
#initialize(input_path: nil, output_path: nil, input_blob: nil, output_blob: nil, compatibility_level: '1.4', pdf_setting: '/printer') ⇒ Compressor
constructor
A new instance of Compressor.
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger
Constructor Details
#initialize(input_path: nil, output_path: nil, input_blob: nil, output_blob: nil, compatibility_level: '1.4', pdf_setting: '/printer') ⇒ Compressor
Returns a new instance of Compressor.
18 19 20 21 22 23 24 25 |
# File 'app/services/pdf/compressor.rb', line 18 def initialize(input_path: nil, output_path: nil, input_blob: nil, output_blob: nil, compatibility_level: '1.4', pdf_setting: '/printer') @input_path = input_path ? Shellwords.escape(input_path) : nil @output_path = output_path ? Shellwords.escape(output_path) : input_path @input_blob = input_blob @output_blob = output_blob @compatibility_level = validate_compatibility(compatibility_level) @pdf_setting = validate_pdf_setting(pdf_setting) end |
Instance Attribute Details
#compatibility_level ⇒ Object (readonly)
Returns the value of attribute compatibility_level.
7 8 9 |
# File 'app/services/pdf/compressor.rb', line 7 def compatibility_level @compatibility_level end |
#input_blob ⇒ Object (readonly)
Returns the value of attribute input_blob.
7 8 9 |
# File 'app/services/pdf/compressor.rb', line 7 def input_blob @input_blob end |
#input_path ⇒ Object (readonly)
Returns the value of attribute input_path.
7 8 9 |
# File 'app/services/pdf/compressor.rb', line 7 def input_path @input_path end |
#output_blob ⇒ Object (readonly)
Returns the value of attribute output_blob.
7 8 9 |
# File 'app/services/pdf/compressor.rb', line 7 def output_blob @output_blob end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
7 8 9 |
# File 'app/services/pdf/compressor.rb', line 7 def output_path @output_path end |
#pdf_setting ⇒ Object (readonly)
Returns the value of attribute pdf_setting.
7 8 9 |
# File 'app/services/pdf/compressor.rb', line 7 def pdf_setting @pdf_setting end |
Instance Method Details
#compress ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/pdf/compressor.rb', line 27 def compress unless gs_available? handle_missing_gs return Result.new(result: :skipped, message: 'Ghostscript not available, file copied or left unchanged', input_path:, output_path:) end if input_blob compress_blob else compress_file end end |