Class: Uniword::Validators::ParagraphValidator

Inherits:
ElementValidator show all
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

Examples:

Using the paragraph validator

validator = Uniword::Validators::ParagraphValidator.new
validator.valid?(paragraph) # => true or false
validator.errors(paragraph) # => ["error message", ...]

Instance Method Summary collapse

Methods inherited from ElementValidator

for, register, reset_registry, validator_registry

Instance Method Details

#errors(element) ⇒ Array<String>

Get validation errors for a paragraph

Parameters:

  • element (Paragraph)

    The paragraph to validate

Returns:

  • (Array<String>)

    Array of error messages



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

Parameters:

  • element (Paragraph)

    The paragraph to validate

Returns:

  • (Boolean)

    true if valid, false otherwise



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