Class: Uniword::Batch::QualityCheckStage

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

Overview

Processing stage that runs quality checks on documents.

Responsibility: Run document quality checker with configured rules. Single Responsibility - only handles quality checking.

Examples:

Use in pipeline

stage = QualityCheckStage.new(
  rules_file: 'config/quality_rules.yml',
  fail_on_errors: false
)
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 = {}) ⇒ QualityCheckStage

Initialize quality check stage

Parameters:

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

    Stage options

Options Hash (options):

  • :rules_file (String)

    Path to quality rules configuration

  • :fail_on_errors (Boolean)

    Raise error if quality errors found

  • :fail_on_warnings (Boolean)

    Raise error if warnings found

  • :generate_report (Boolean)

    Generate quality report file



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

def initialize(options = {})
  super
  @rules_file = options[:rules_file]
  @fail_on_errors = options.fetch(:fail_on_errors, false)
  @fail_on_warnings = options.fetch(:fail_on_warnings, false)
  @generate_report = options.fetch(:generate_report, true)

  # Initialize quality checker
  @checker = initialize_checker
end

Instance Method Details

#descriptionString

Get stage description

Returns:

  • (String)

    Description



65
66
67
# File 'lib/uniword/batch/stages/quality_check_stage.rb', line 65

def description
  "Run quality checks"
end

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

Process document to run quality checks

Parameters:

  • document (Document)

    Document to process

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

    Processing context

Returns:

  • (Document)

    Processed document

Raises:

  • (QualityCheckError)

    if quality checks fail and fail_on_errors is true



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/uniword/batch/stages/quality_check_stage.rb', line 41

def process(document, context = {})
  log "Running quality checks on #{context[:filename]}"

  # Run quality checker
  report = @checker.check(document)

  # Log results
  log_report_summary(report)

  # Generate report file if requested
  if @generate_report && context[:output_path]
    generate_report_file(report,
                         context)
  end

  # Check if we should fail
  check_failure_conditions(report, context[:filename])

  document
end