Class: Uniword::Batch::ProcessingStage

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/batch/processing_stage.rb

Overview

Base class for batch processing pipeline stages.

Responsibility: Define the interface for processing pipeline stages. Each stage performs one specific transformation or validation on a document.

Follows Single Responsibility Principle - one stage does one transformation. Follows Open/Closed Principle - new stages can be added without modifying this class.

Examples:

Create a custom processing stage

class CustomStage < ProcessingStage
  def initialize(options = {})
    super(options)
    @threshold = options[:threshold] || 100
  end

  def process(document, context = {})
    # Perform transformation
    # Return modified document or original
    document
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProcessingStage

Initialize processing stage

Parameters:

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

    Stage configuration options

Options Hash (options):

  • :enabled (Boolean)

    Whether stage is enabled (default: true)



33
34
35
36
# File 'lib/uniword/batch/processing_stage.rb', line 33

def initialize(options = {})
  @options = options || {}
  @enabled = @options.fetch(:enabled, true)
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled.



27
28
29
# File 'lib/uniword/batch/processing_stage.rb', line 27

def enabled
  @enabled
end

#optionsObject (readonly)

Returns the value of attribute options.



27
28
29
# File 'lib/uniword/batch/processing_stage.rb', line 27

def options
  @options
end

Instance Method Details

#descriptionString

Get stage description (for logging and reporting)

Returns:

  • (String)

    Stage description



69
70
71
# File 'lib/uniword/batch/processing_stage.rb', line 69

def description
  "#{name} stage"
end

#enabled?Boolean

Check if stage is enabled

Returns:

  • (Boolean)

    true if stage should be executed



41
42
43
# File 'lib/uniword/batch/processing_stage.rb', line 41

def enabled?
  @enabled
end

#nameString

Get stage name (used for identification and logging)

Returns:

  • (String)

    Stage name



58
59
60
61
62
63
64
# File 'lib/uniword/batch/processing_stage.rb', line 58

def name
  self.class.name.split("::").last
    .gsub(/Stage$/, "")
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .downcase
end

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

Process a document through this stage

Parameters:

  • document (Document)

    The document to process

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

    Processing context (file paths, metadata, etc.)

Returns:

  • (Document)

    The processed document (may be modified or original)

Raises:

  • (NotImplementedError)

    if not implemented by subclass



51
52
53
# File 'lib/uniword/batch/processing_stage.rb', line 51

def process(document, context = {})
  raise NotImplementedError, "#{self.class} must implement #process"
end