Class: Fontisan::Validation::Woff2Validator
- Inherits:
-
Object
- Object
- Fontisan::Validation::Woff2Validator
- Defined in:
- lib/fontisan/validation/woff2_validator.rb
Overview
Woff2Validator is the main orchestrator for WOFF2 font validation
This class coordinates WOFF2-specific validation checks (header, tables) and produces a comprehensive ValidationReport. It is designed to validate WOFF2 encoding quality and spec compliance.
Single Responsibility: Orchestration of WOFF2 validation workflow
Constant Summary collapse
- LEVELS =
Validation levels
%i[strict standard lenient].freeze
Instance Attribute Summary collapse
-
#level ⇒ Symbol
readonly
Get the current validation level.
Instance Method Summary collapse
-
#initialize(level: :standard, rules_path: nil) ⇒ Woff2Validator
constructor
Initialize WOFF2 validator.
-
#validate(woff2_font, font_path) ⇒ Models::ValidationReport
Validate a WOFF2 font.
Constructor Details
#initialize(level: :standard, rules_path: nil) ⇒ Woff2Validator
Initialize WOFF2 validator
36 37 38 39 40 41 42 43 |
# File 'lib/fontisan/validation/woff2_validator.rb', line 36 def initialize(level: :standard, rules_path: nil) @level = level validate_level! @rules = load_rules(rules_path) @header_validator = Woff2HeaderValidator.new(@rules) @table_validator = Woff2TableValidator.new(@rules) end |
Instance Attribute Details
#level ⇒ Symbol (readonly)
Get the current validation level
97 98 99 |
# File 'lib/fontisan/validation/woff2_validator.rb', line 97 def level @level end |
Instance Method Details
#validate(woff2_font, font_path) ⇒ Models::ValidationReport
Validate a WOFF2 font
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fontisan/validation/woff2_validator.rb', line 50 def validate(woff2_font, font_path) report = Models::ValidationReport.new( font_path: font_path, valid: true, ) begin # Run all validation checks all_issues = [] # 1. Header validation all_issues.concat(@header_validator.validate(woff2_font)) # 2. Table validation all_issues.concat(@table_validator.validate(woff2_font)) # 3. WOFF2-specific checks all_issues.concat(check_woff2_specific(woff2_font)) # Add issues to report all_issues.each do |issue| case issue[:severity] when "error" report.add_error(issue[:category], issue[:message], issue[:location]) when "warning" report.add_warning(issue[:category], issue[:message], issue[:location]) when "info" report.add_info(issue[:category], issue[:message], issue[:location]) end end # Determine overall validity based on level report.valid = determine_validity(report) rescue StandardError => e report.add_error("woff2_validation", "WOFF2 validation failed: #{e.}", nil) report.valid = false end report end |