Class: Fontisan::Validators::ProfileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/validators/profile_loader.rb

Overview

ProfileLoader manages validation profiles and loads appropriate validators

This class provides a registry of validation profiles, each configured for specific use cases. Profiles define which validator to use, loading mode, and severity thresholds.

Available profiles:

  • indexability: Fast validation for font discovery (BasicValidator)

  • usability: Basic usability for installation (FontBookValidator)

  • production: Comprehensive quality checks (OpenTypeValidator)

  • web: Web embedding and optimization (WebFontValidator)

  • spec_compliance: Full OpenType spec compliance (OpenTypeValidator)

  • default: Alias for production profile

Examples:

Loading a profile

validator = ProfileLoader.load(:production)
report = validator.validate(font)

Getting profile info

info = ProfileLoader.profile_info(:web)
puts info[:description]

Constant Summary collapse

PROFILES =

Profile definitions (hardcoded, no YAML)

{
  indexability: {
    name: "Font Indexability",
    description: "Fast validation for font discovery and indexing",
    validator: "BasicValidator",
    loading_mode: "metadata",
    severity_threshold: "error",
  },
  usability: {
    name: "Font Usability",
    description: "Basic usability for installation",
    validator: "FontBookValidator",
    loading_mode: "full",
    severity_threshold: "warning",
  },
  production: {
    name: "Production Quality",
    description: "Comprehensive quality checks",
    validator: "OpenTypeValidator",
    loading_mode: "full",
    severity_threshold: "warning",
  },
  web: {
    name: "Web Font Readiness",
    description: "Web embedding and optimization",
    validator: "WebFontValidator",
    loading_mode: "full",
    severity_threshold: "warning",
  },
  spec_compliance: {
    name: "OpenType Specification",
    description: "Full OpenType spec compliance",
    validator: "OpenTypeValidator",
    loading_mode: "full",
    severity_threshold: "info",
  },
  default: {
    name: "Default Profile",
    description: "Default validation profile (alias for production)",
    validator: "OpenTypeValidator",
    loading_mode: "full",
    severity_threshold: "warning",
  },
}.freeze

Class Method Summary collapse

Class Method Details

.all_profilesHash

Get all profiles with their configurations

Examples:

Get all profiles

ProfileLoader.all_profiles.each do |name, config|
  puts "#{name}: #{config[:description]}"
end

Returns:

  • (Hash)

    All profile configurations



133
134
135
# File 'lib/fontisan/validators/profile_loader.rb', line 133

def all_profiles
  PROFILES
end

.available_profilesArray<Symbol>

Get list of available profile names

Examples:

List available profiles

ProfileLoader.available_profiles
# => [:indexability, :usability, :production, :web, :spec_compliance, :default]

Returns:

  • (Array<Symbol>)

    Array of profile names



109
110
111
# File 'lib/fontisan/validators/profile_loader.rb', line 109

def available_profiles
  PROFILES.keys
end

.load(profile_name) ⇒ Validator

Load a validator for the specified profile

Examples:

Load production validator

validator = ProfileLoader.load(:production)

Parameters:

  • profile_name (Symbol, String)

    Profile name

Returns:

  • (Validator)

    Validator instance for the profile

Raises:

  • (ArgumentError)

    if profile name is unknown



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fontisan/validators/profile_loader.rb', line 87

def load(profile_name)
  profile_name = profile_name.to_sym
  profile_config = PROFILES[profile_name]

  unless profile_config
    raise ArgumentError,
          "Unknown profile: #{profile_name}. " \
          "Available profiles: #{available_profiles.join(', ')}"
  end

  validator_class_name = profile_config[:validator]
  validator_class = Validators.const_get(validator_class_name)
  validator_class.new
end

.profile_info(profile_name) ⇒ Hash?

Get profile configuration

Examples:

Get profile info

info = ProfileLoader.profile_info(:web)
puts info[:description]

Parameters:

  • profile_name (Symbol, String)

    Profile name

Returns:

  • (Hash, nil)

    Profile configuration or nil if not found



121
122
123
# File 'lib/fontisan/validators/profile_loader.rb', line 121

def profile_info(profile_name)
  PROFILES[profile_name.to_sym]
end