Class: Uniword::Accessibility::AccessibilityProfile

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

Overview

Accessibility Profile - configuration for accessibility checking profile

Responsibility: Load and manage profile configuration Single Responsibility: Profile configuration management only

Examples:

Loading a profile

config = YAML.load_file('config/accessibility_profiles.yml')
profile = AccessibilityProfile.load(config, :wcag_2_1_aa)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, all_profiles = {}) ⇒ AccessibilityProfile

Initialize a new accessibility profile

Parameters:

  • config (Hash)

    Profile configuration

  • all_profiles (Hash) (defaults to: {})

    All available profiles (for inheritance)



42
43
44
45
46
47
48
49
50
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 42

def initialize(config, all_profiles = {})
  @config = config
  @all_profiles = all_profiles
  @name = config[:name] || config["name"]
  @level = config[:level] || config["level"]
  @inherits = config[:inherits] || config["inherits"]
  @overrides = config[:overrides] || config["overrides"] || {}
  @rules = build_rules_config
end

Instance Attribute Details

#inheritsObject (readonly)

Returns the value of attribute inherits.



14
15
16
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 14

def inherits
  @inherits
end

#levelObject (readonly)

Returns the value of attribute level.



14
15
16
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 14

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 14

def name
  @name
end

#overridesObject (readonly)

Returns the value of attribute overrides.



14
15
16
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 14

def overrides
  @overrides
end

#rulesObject (readonly)

Returns the value of attribute rules.



14
15
16
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 14

def rules
  @rules
end

Class Method Details

.load(config, profile_name) ⇒ AccessibilityProfile

Load a profile from configuration

Parameters:

  • config (Hash)

    Full configuration with profiles

  • profile_name (Symbol)

    Name of profile to load

Returns:

Raises:

  • (ArgumentError)

    If profile not found



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 22

def self.load(config, profile_name)
  profiles_config = config[:profiles] || config["profiles"]
  unless profiles_config
    raise ArgumentError,
          "No profiles found in configuration"
  end

  profile_config = profiles_config[profile_name] || profiles_config[profile_name.to_s]
  unless profile_config
    raise ArgumentError,
          "Profile '#{profile_name}' not found"
  end

  new(profile_config, profiles_config)
end

Instance Method Details

#rule_config(rule_name) ⇒ Hash?

Get configuration for a specific rule

Parameters:

  • rule_name (Symbol, String)

    Rule name

Returns:

  • (Hash, nil)

    Rule configuration or nil



56
57
58
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 56

def rule_config(rule_name)
  @rules[rule_name.to_sym] || @rules[rule_name.to_s]
end

#rule_enabled?(rule_name) ⇒ Boolean

Check if a rule is enabled

Parameters:

  • rule_name (Symbol, String)

    Rule name

Returns:

  • (Boolean)

    True if rule is enabled



64
65
66
67
68
69
# File 'lib/uniword/accessibility/accessibility_profile.rb', line 64

def rule_enabled?(rule_name)
  config = rule_config(rule_name)
  return false unless config

  config.fetch(:enabled, config.fetch("enabled", true))
end