Class: Uniword::Quality::DocumentChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/quality/document_checker.rb

Overview

Coordinates document quality checking using configured rules.

Responsibility: Load rules from configuration and orchestrate quality checks. Single Responsibility - only coordinates rule execution and report generation.

Follows Open/Closed Principle - new rules can be added via configuration without modifying this class.

Examples:

Check document quality

checker = DocumentChecker.new
report = checker.check(document)
puts report.valid? ? "OK" : "Issues found"

Use custom rules file

checker = DocumentChecker.new(rules_file: 'custom_rules.yml')
report = checker.check(document)

Constant Summary collapse

RULE_CLASSES =

Rule class registry Maps rule names to their class implementations

{
  heading_hierarchy: "HeadingHierarchyRule",
  table_headers: "TableHeaderRule",
  paragraph_length: "ParagraphLengthRule",
  image_alt_text: "ImageAltTextRule",
  link_validation: "LinkValidationRule",
  style_consistency: "StyleConsistencyRule",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules_file: nil, config: nil) ⇒ DocumentChecker

Initialize document checker

Parameters:

  • rules_file (String, nil) (defaults to: nil)

    Path to rules configuration file

  • config (Hash, nil) (defaults to: nil)

    Direct configuration hash (overrides rules_file)



42
43
44
45
# File 'lib/uniword/quality/document_checker.rb', line 42

def initialize(rules_file: nil, config: nil)
  @config = load_configuration(rules_file, config)
  @rules = load_rules
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



25
26
27
# File 'lib/uniword/quality/document_checker.rb', line 25

def config
  @config
end

#rulesObject (readonly)

Returns the value of attribute rules.



25
26
27
# File 'lib/uniword/quality/document_checker.rb', line 25

def rules
  @rules
end

Instance Method Details

#check(document) ⇒ QualityReport

Check document for quality violations

Parameters:

  • document (Document)

    The document to check

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/uniword/quality/document_checker.rb', line 51

def check(document)
  validate_document!(document)

  report = QualityReport.new

  # Execute each enabled rule
  rules.each do |rule|
    next unless rule.enabled?

    violations = rule.check(document)
    report.add_violations(violations)
  end

  report
end

#disabled_rulesArray<String>

Get list of disabled rule names

Returns:

  • (Array<String>)

    Names of disabled rules



77
78
79
# File 'lib/uniword/quality/document_checker.rb', line 77

def disabled_rules
  rules.reject(&:enabled?).map(&:name)
end

#enabled_rulesArray<String>

Get list of enabled rule names

Returns:

  • (Array<String>)

    Names of enabled rules



70
71
72
# File 'lib/uniword/quality/document_checker.rb', line 70

def enabled_rules
  rules.select(&:enabled?).map(&:name)
end