Class: Uniword::Validation::VerifyOrchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/validation/verify_orchestrator.rb

Overview

Orchestrates the three-layer DOCX verification process.

Coordinates:

  1. OPC Package validation (ZIP, content types, relationships)

  2. XSD Schema validation (namespace-aware, using Moxml + Nokogiri)

  3. Word Document semantic validation (extensible rule system)

Returns a VerificationReport that can be serialized to JSON/YAML or formatted for terminal output.

Examples:

Verify a DOCX file

orchestrator = VerifyOrchestrator.new
report = orchestrator.verify("document.docx")
puts report.to_json
puts TerminalFormatter.new.format(report)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xsd_validation: false) ⇒ VerifyOrchestrator

Initialize the orchestrator.

Parameters:

  • xsd_validation (Boolean) (defaults to: false)

    Enable XSD schema validation



35
36
37
# File 'lib/uniword/validation/verify_orchestrator.rb', line 35

def initialize(xsd_validation: false)
  @xsd_validation = xsd_validation
end

Instance Attribute Details

#xsd_validationObject (readonly)

Returns the value of attribute xsd_validation.



30
31
32
# File 'lib/uniword/validation/verify_orchestrator.rb', line 30

def xsd_validation
  @xsd_validation
end

Instance Method Details

#verify(path) ⇒ Report::VerificationReport

Verify a DOCX file.

Parameters:

  • path (String)

    Path to .docx file

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/uniword/validation/verify_orchestrator.rb', line 43

def verify(path)
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  layers = []

  # Layer 1: OPC Package
  opc_layer = run_opc_layer(path)
  layers << opc_layer

  # Only skip downstream layers for critical OPC failures:
  # ZIP can't be opened (OPC-001) or word/document.xml missing (OPC-004)
  critical_failure = opc_layer.issues.any? do |i|
    %w[OPC-001 OPC-004].include?(i.code)
  end

  if critical_failure
    layers << Report::LayerResult.new(
      name: "XSD Schema", status: "skipped", duration_ms: 0, issues: [],
    )
    layers << Report::LayerResult.new(
      name: "Word Document", status: "skipped", duration_ms: 0, issues: [],
    )
  else
    layers << run_xsd_layer(path)
    layers << run_semantic_layer(path)
  end

  end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  total_ms = ((end_time - start_time) * 1000).round

  Report::VerificationReport.new(
    file_path: path,
    valid: layers.all?(&:pass?),
    duration_ms: total_ms,
    layers: layers,
  )
end