Class: Uniword::Batch::NormalizeStylesStage

Inherits:
ProcessingStage show all
Defined in:
lib/uniword/batch/stages/normalize_styles_stage.rb

Overview

Processing stage that normalizes document styles.

Responsibility: Remove direct formatting and apply standard styles. Single Responsibility - only handles style normalization.

Examples:

Use in pipeline

stage = NormalizeStylesStage.new(
  remove_direct_formatting: true,
  apply_standard_styles: true
)
document = stage.process(document, context)

Instance Attribute Summary

Attributes inherited from ProcessingStage

#enabled, #options

Instance Method Summary collapse

Methods inherited from ProcessingStage

#enabled?, #name

Constructor Details

#initialize(options = {}) ⇒ NormalizeStylesStage

Initialize normalize styles stage

Parameters:

  • options (Hash) (defaults to: {})

    Stage options

Options Hash (options):

  • :remove_direct_formatting (Boolean)

    Remove direct formatting

  • :apply_standard_styles (Boolean)

    Apply standard styles

  • :preserve_semantic_styles (Boolean)

    Preserve semantic styles

  • :target_styles (Hash)

    Target style mappings



24
25
26
27
28
29
30
31
32
# File 'lib/uniword/batch/stages/normalize_styles_stage.rb', line 24

def initialize(options = {})
  super
  @remove_direct_formatting = options.fetch(:remove_direct_formatting,
                                            true)
  @apply_standard_styles = options.fetch(:apply_standard_styles, true)
  @preserve_semantic_styles = options.fetch(:preserve_semantic_styles,
                                            true)
  @target_styles = options.fetch(:target_styles, default_target_styles)
end

Instance Method Details

#descriptionString

Get stage description

Returns:

  • (String)

    Description



52
53
54
# File 'lib/uniword/batch/stages/normalize_styles_stage.rb', line 52

def description
  "Normalize document styles"
end

#process(document, context = {}) ⇒ Document

Process document to normalize styles

Parameters:

  • document (Document)

    Document to process

  • context (Hash) (defaults to: {})

    Processing context

Returns:

  • (Document)

    Processed document



39
40
41
42
43
44
45
46
47
# File 'lib/uniword/batch/stages/normalize_styles_stage.rb', line 39

def process(document, context = {})
  log "Normalizing styles in #{context[:filename]}"

  normalize_paragraph_styles(document) if @apply_standard_styles
  remove_direct_formatting_from_runs(document) if @remove_direct_formatting

  log "Style normalization complete"
  document
end