Class: Uniword::Validation::StructuralValidator
- Inherits:
-
Object
- Object
- Uniword::Validation::StructuralValidator
- Defined in:
- lib/uniword/validation/structural_validator.rb
Overview
Validates in-memory DocumentRoot structure.
Performs structural checks on the document model without requiring file access. Complements DocumentValidator (file-level 7-layer pipeline) for quick in-process validation.
Follows Open/Closed: add new check methods and register them in CHECKS without modifying existing code.
Constant Summary collapse
- CHECKS =
Registered check methods. Each returns an array of { severity:, message: } hashes.
%i[ check_body_present check_bookmark_pairing check_bookmark_uniqueness check_empty_paragraphs ].freeze
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#errors ⇒ Array<String>
Error messages (severity: error).
-
#initialize(document) ⇒ StructuralValidator
constructor
A new instance of StructuralValidator.
-
#issues ⇒ Array<Hash>
All issues.
-
#valid? ⇒ Boolean
True if no errors (warnings are non-fatal).
-
#warnings ⇒ Array<String>
Warning messages (severity: warning).
Constructor Details
#initialize(document) ⇒ StructuralValidator
Returns a new instance of StructuralValidator.
31 32 33 |
# File 'lib/uniword/validation/structural_validator.rb', line 31 def initialize(document) @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
29 30 31 |
# File 'lib/uniword/validation/structural_validator.rb', line 29 def document @document end |
Instance Method Details
#errors ⇒ Array<String>
Returns Error messages (severity: error).
41 42 43 44 45 |
# File 'lib/uniword/validation/structural_validator.rb', line 41 def errors @errors ||= issues .select { |i| i[:severity] == :error } .map { |i| i[:message] } end |
#issues ⇒ Array<Hash>
Returns All issues.
55 56 57 |
# File 'lib/uniword/validation/structural_validator.rb', line 55 def issues @issues ||= CHECKS.flat_map { |check| send(check) } end |
#valid? ⇒ Boolean
Returns true if no errors (warnings are non-fatal).
36 37 38 |
# File 'lib/uniword/validation/structural_validator.rb', line 36 def valid? errors.empty? end |
#warnings ⇒ Array<String>
Returns Warning messages (severity: warning).
48 49 50 51 52 |
# File 'lib/uniword/validation/structural_validator.rb', line 48 def warnings @warnings ||= issues .select { |i| i[:severity] == :warning } .map { |i| i[:message] } end |