Class: Lutaml::Xsd::Validation::Rules::OccurrenceValidationRule

Inherits:
ValidationRule
  • Object
show all
Defined in:
lib/lutaml/xsd/validation/rules/occurrence_validation_rule.rb

Overview

OccurrenceValidationRule validates occurrence constraints

This rule checks:

  • minOccurs constraint is satisfied

  • maxOccurs constraint is satisfied (including unbounded)

  • Element occurrence counts

  • Reports violations with expected vs actual counts

Based on Jing validator occurrence validation algorithm.

Examples:

Using the rule

rule = OccurrenceValidationRule.new
rule.validate(parent_element, schema_particle, collector)

See Also:

  • Occurrence Validation

Constant Summary

Constants inherited from ValidationRule

ValidationRule::CATEGORIES

Instance Attribute Summary

Attributes inherited from ValidationRule

#options

Instance Method Summary collapse

Methods inherited from ValidationRule

#applicable?, #disable!, #enable!, #enabled?, #initialize, #inspect, #option, #priority, #to_h, #to_s

Constructor Details

This class inherits a constructor from Lutaml::Xsd::Validation::ValidationRule

Instance Method Details

#categorySymbol

Rule category

Returns:

  • (Symbol)

    :constraint



28
29
30
# File 'lib/lutaml/xsd/validation/rules/occurrence_validation_rule.rb', line 28

def category
  :constraint
end

#descriptionString

Rule description

Returns:

  • (String)


35
36
37
# File 'lib/lutaml/xsd/validation/rules/occurrence_validation_rule.rb', line 35

def description
  "Validates minOccurs and maxOccurs constraints on elements"
end

#validate(parent_element, schema_particle, collector) ⇒ void

This method returns an undefined value.

Validate occurrence constraints

Validates that elements appear the correct number of times according to their minOccurs and maxOccurs constraints.

Parameters:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lutaml/xsd/validation/rules/occurrence_validation_rule.rb', line 49

def validate(parent_element, schema_particle, collector)
  return unless schema_particle
  return unless parent_element

  # Handle different particle types
  case schema_particle
  when Lutaml::Xsd::Element
    validate_element_occurrence(parent_element, schema_particle,
                                collector)
  when Lutaml::Xsd::Sequence
    validate_sequence_occurrences(parent_element, schema_particle,
                                  collector)
  when Lutaml::Xsd::Choice
    validate_choice_occurrences(parent_element, schema_particle,
                                collector)
  when Lutaml::Xsd::All
    validate_all_occurrences(parent_element, schema_particle,
                             collector)
  end
end