Class: Uniword::Accessibility::AccessibilityChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/accessibility/accessibility_checker.rb

Overview

Accessibility Checker - validate document accessibility compliance

Responsibility: Orchestrate accessibility checking with profiles Single Responsibility: Accessibility validation orchestration only

External config: config/accessibility_profiles.yml

Examples:

Check document accessibility

checker = AccessibilityChecker.new(profile: :wcag_2_1_aa)
report = checker.check(document)
puts report.summary
report.export_html('accessibility_report.html')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile: :wcag_2_1_aa, config_file: nil) ⇒ AccessibilityChecker

Initialize a new accessibility checker

Parameters:

  • profile (Symbol) (defaults to: :wcag_2_1_aa)

    Profile name to use

  • config_file (String) (defaults to: nil)

    Path to configuration file

Raises:

  • (ArgumentError)

    If profile not found



27
28
29
30
31
32
33
# File 'lib/uniword/accessibility/accessibility_checker.rb', line 27

def initialize(profile: :wcag_2_1_aa, config_file: nil)
  @profile_name = profile
  @config_file = config_file || default_config_path
  @config = load_config
  @profile = AccessibilityProfile.load(@config, @profile_name)
  @rules = initialize_rules
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



20
21
22
# File 'lib/uniword/accessibility/accessibility_checker.rb', line 20

def profile
  @profile
end

#rulesObject (readonly)

Returns the value of attribute rules.



20
21
22
# File 'lib/uniword/accessibility/accessibility_checker.rb', line 20

def rules
  @rules
end

Instance Method Details

#check(document) ⇒ AccessibilityReport

Check document for accessibility compliance

Parameters:

  • document (Document)

    Document to check

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/uniword/accessibility/accessibility_checker.rb', line 39

def check(document)
  report = AccessibilityReport.new(
    profile_name: @profile.name,
    profile_level: @profile.level,
  )

  # Run all enabled rules
  @rules.each do |rule|
    next unless rule.enabled?

    violations = rule.check(document)
    violations.each { |v| report.add_violation(v) }
  end

  report
end

#compliant?(document) ⇒ Boolean

Quick compliance check (boolean)

Parameters:

  • document (Document)

    Document to check

Returns:

  • (Boolean)

    True if compliant (no errors)



60
61
62
# File 'lib/uniword/accessibility/accessibility_checker.rb', line 60

def compliant?(document)
  check(document).compliant?
end