Class: Uniword::Validators::ParagraphValidator
- Inherits:
-
ElementValidator
- Object
- ElementValidator
- Uniword::Validators::ParagraphValidator
- Defined in:
- lib/uniword/validators/paragraph_validator.rb
Overview
Validator for Paragraph elements Responsibility: Validate paragraph-specific constraints
A valid paragraph:
-
Must be a Paragraph instance
-
Can have zero or more runs (empty paragraphs are valid)
-
All runs must be valid Run instances
-
Properties, if present, must be valid ParagraphProperties
Instance Method Summary collapse
-
#errors(element) ⇒ Array<String>
Get validation errors for a paragraph.
-
#valid?(element) ⇒ Boolean
Validate a paragraph element.
Methods inherited from ElementValidator
for, register, reset_registry, validator_registry
Instance Method Details
#errors(element) ⇒ Array<String>
Get validation errors for a paragraph
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/uniword/validators/paragraph_validator.rb', line 38 def errors(element) errors = [] # Check if element is nil return ["Element is nil"] if element.nil? # Check paragraph type first (more specific than base check) return ["Element must be a Paragraph"] unless element.is_a?(Uniword::Wordprocessingml::Paragraph) # Validate runs - collect all specific errors errors.concat(run_errors(element)) # Validate properties - collect all specific errors errors.concat(property_errors(element)) errors end |
#valid?(element) ⇒ Boolean
Validate a paragraph element
26 27 28 29 30 31 32 |
# File 'lib/uniword/validators/paragraph_validator.rb', line 26 def valid?(element) return false unless super return false unless element.is_a?(Uniword::Wordprocessingml::Paragraph) validate_runs(element) && validate_properties(element) end |