Class: Uniword::Accessibility::Rules::TableHeadersRule
- Inherits:
-
AccessibilityRule
- Object
- AccessibilityRule
- Uniword::Accessibility::Rules::TableHeadersRule
- Defined in:
- lib/uniword/accessibility/rules/table_headers_rule.rb
Overview
Table Headers Rule - WCAG 1.3.1 Info and Relationships
Responsibility: Check that tables have proper headers Single Responsibility: Table header validation only
WCAG 1.3.1 Level A: Data tables must have headers
Instance Attribute Summary
Attributes inherited from AccessibilityRule
#config, #level, #rule_id, #wcag_criterion
Instance Method Summary collapse
-
#check(document) ⇒ Array<AccessibilityViolation>
Check document tables for headers.
Methods inherited from AccessibilityRule
Constructor Details
This class inherits a constructor from Uniword::Accessibility::AccessibilityRule
Instance Method Details
#check(document) ⇒ Array<AccessibilityViolation>
Check document tables for headers
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/uniword/accessibility/rules/table_headers_rule.rb', line 17 def check(document) violations = [] document.tables.each_with_index do |table, index| # Check if table has header row has_header = table.rows.first&.header? unless has_header violations << create_violation( message: "Table #{index + 1} missing header row", element: table, severity: @config[:severity] || :error, suggestion: @config[:suggestion] || "Mark first row as header: table.rows.first.header = true", ) end # Check for caption if required next unless @config[:require_caption] && !table_has_caption?(table) violations << create_violation( message: "Table #{index + 1} missing caption", element: table, severity: :warning, suggestion: "Add table caption to describe the data presented", ) end violations end |