Class: Uniword::Batch::ConvertFormatStage
- Inherits:
-
ProcessingStage
- Object
- ProcessingStage
- Uniword::Batch::ConvertFormatStage
- Defined in:
- lib/uniword/batch/stages/convert_format_stage.rb
Overview
Processing stage that converts document format.
Responsibility: Convert documents between DOCX and MHTML formats. Single Responsibility - only handles format conversion.
Instance Attribute Summary
Attributes inherited from ProcessingStage
Instance Method Summary collapse
-
#description ⇒ String
Get stage description.
-
#initialize(options = {}) ⇒ ConvertFormatStage
constructor
Initialize convert format stage.
-
#process(document, context = {}) ⇒ Document
Process document to convert format.
Methods inherited from ProcessingStage
Constructor Details
#initialize(options = {}) ⇒ ConvertFormatStage
Initialize convert format stage
22 23 24 25 26 27 28 |
# File 'lib/uniword/batch/stages/convert_format_stage.rb', line 22 def initialize( = {}) super @target_format = .fetch(:target_format, :docx) @preserve_original = .fetch(:preserve_original, true) validate_target_format! end |
Instance Method Details
#description ⇒ String
Get stage description
62 63 64 |
# File 'lib/uniword/batch/stages/convert_format_stage.rb', line 62 def description "Convert document format to #{@target_format}" end |
#process(document, context = {}) ⇒ Document
Process document to convert format
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/uniword/batch/stages/convert_format_stage.rb', line 35 def process(document, context = {}) log "Converting to #{@target_format} format: #{context[:filename]}" # Detect current format from file extension current_format = detect_format(context[:input_path]) # Skip if already in target format if current_format == @target_format log "Document already in #{@target_format} format, skipping conversion" return document end # Update output path extension if needed if context[:output_path] context[:output_path] = update_output_extension( context[:output_path], @target_format, ) end log "Format conversion complete" document end |