Class: Uniword::Validators::TableValidator
- Inherits:
-
ElementValidator
- Object
- ElementValidator
- Uniword::Validators::TableValidator
- Defined in:
- lib/uniword/validators/table_validator.rb
Overview
Validator for Table elements Responsibility: Validate table-specific constraints
A valid table:
-
Must be a Table instance
-
Can have zero or more rows (empty tables are valid)
-
All rows must be valid TableRow instances
-
All rows should have consistent column counts (warning, not error)
-
Properties, if present, must be valid TableProperties
Instance Method Summary collapse
-
#errors(element) ⇒ Array<String>
Get validation errors for a table.
-
#valid?(element) ⇒ Boolean
Validate a table element.
-
#warnings(element) ⇒ Array<String>
Get validation warnings (non-critical issues).
Methods inherited from ElementValidator
for, register, reset_registry, validator_registry
Instance Method Details
#errors(element) ⇒ Array<String>
Get validation errors for a table
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/uniword/validators/table_validator.rb', line 39 def errors(element) errors = [] # Check if element is nil return ["Element is nil"] if element.nil? # Check table type first (more specific than base check) return ["Element must be a Table"] unless element.is_a?(Uniword::Wordprocessingml::Table) # Validate rows - collect all specific errors errors.concat(row_errors(element)) # Validate properties - collect all specific errors errors.concat(property_errors(element)) errors end |
#valid?(element) ⇒ Boolean
Validate a table element
27 28 29 30 31 32 33 |
# File 'lib/uniword/validators/table_validator.rb', line 27 def valid?(element) return false unless super return false unless element.is_a?(Uniword::Wordprocessingml::Table) validate_rows(element) && validate_properties(element) end |
#warnings(element) ⇒ Array<String>
Get validation warnings (non-critical issues)
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/uniword/validators/table_validator.rb', line 61 def warnings(element) warnings = [] return warnings unless element.is_a?(Uniword::Wordprocessingml::Table) return warnings if element.rows.empty? # Check for inconsistent column counts column_counts = element.rows.map { |row| row.cells.count }.uniq warnings << "Table has inconsistent column counts: #{column_counts.join(', ')}" if column_counts.size > 1 warnings end |