Class: Uniword::Quality::TableHeaderRule

Inherits:
QualityRule show all
Defined in:
lib/uniword/quality/rules/table_header_rule.rb

Overview

Checks that tables have proper header rows.

Responsibility: Validate table structure and headers. Single Responsibility - only checks table headers.

Validates:

  • Tables have at least one header row

  • Header rows are properly marked

  • Tables are accessible

Examples:

Configuration

table_headers:
  enabled: true
  require_headers: true

Instance Attribute Summary

Attributes inherited from QualityRule

#config, #enabled

Instance Method Summary collapse

Methods inherited from QualityRule

#enabled?, #name

Constructor Details

#initialize(config = {}) ⇒ TableHeaderRule

Returns a new instance of TableHeaderRule.



20
21
22
23
# File 'lib/uniword/quality/rules/table_header_rule.rb', line 20

def initialize(config = {})
  super
  @require_headers = @config.fetch(:require_headers, true)
end

Instance Method Details

#check(document) ⇒ Array<QualityViolation>

Check document for table header violations

Parameters:

  • document (Document)

    The document to check

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/uniword/quality/rules/table_header_rule.rb', line 29

def check(document)
  violations = []

  return violations unless @require_headers

  document.tables.each_with_index do |table, index|
    next if has_header_row?(table)

    violations << create_violation(
      severity: :warning,
      message: "Table #{index + 1} does not have a header row. " \
               "Headers improve accessibility and readability.",
      location: "Table #{index + 1}",
      element: table,
    )
  end

  violations
end