Class: Uniword::Accessibility::Rules::DescriptiveHeadingsRule
- Inherits:
-
AccessibilityRule
- Object
- AccessibilityRule
- Uniword::Accessibility::Rules::DescriptiveHeadingsRule
- Defined in:
- lib/uniword/accessibility/rules/descriptive_headings_rule.rb
Overview
Descriptive Headings Rule - WCAG 2.4.6 Headings and Labels
Responsibility: Check that headings are descriptive Single Responsibility: Heading descriptiveness validation only
WCAG 2.4.6 Level AA: Headings and labels describe topic or purpose
Instance Attribute Summary
Attributes inherited from AccessibilityRule
#config, #level, #rule_id, #wcag_criterion
Instance Method Summary collapse
-
#check(document) ⇒ Array<AccessibilityViolation>
Check document headings for descriptiveness.
Methods inherited from AccessibilityRule
Constructor Details
This class inherits a constructor from Uniword::Accessibility::AccessibilityRule
Instance Method Details
#check(document) ⇒ Array<AccessibilityViolation>
Check document headings for descriptiveness
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 47 48 49 50 51 |
# File 'lib/uniword/accessibility/rules/descriptive_headings_rule.rb', line 17 def check(document) violations = [] return violations unless @config[:check_descriptiveness] headings = extract_headings(document) headings.each_with_index do |heading, index| text = extract_heading_text(heading[:paragraph]) # Check minimum length if text && @config[:min_heading_length] && (text.length < @config[:min_heading_length]) violations << create_violation( message: "Heading #{index + 1} is too short to be descriptive: '#{text}'", element: heading[:paragraph], severity: @config[:severity] || :warning, suggestion: @config[:suggestion] || "Use descriptive headings that clearly describe content", ) end # Check for generic headings generic_headings = %w[heading section part introduction conclusion] next unless text && generic_headings.any?(text.downcase) violations << create_violation( message: "Heading #{index + 1} is too generic: '#{text}'", element: heading[:paragraph], severity: :warning, suggestion: "Make headings specific to the content they describe", ) end violations end |