Class: Lutaml::Xml::Decisions::Rules::DefaultPreferenceRule
- Inherits:
-
DecisionRule
- Object
- DecisionRule
- Lutaml::Xml::Decisions::Rules::DefaultPreferenceRule
- Defined in:
- lib/lutaml/xml/decisions/rules/default_preference_rule.rb
Overview
Priority 5: Default preference
When no other rule applies:
-
If namespace has element_form_default :unqualified, prefer prefix format (so children can be unqualified without xmlns=“”)
-
Otherwise, prefer default namespace format (cleaner, no prefix)
Instance Method Summary collapse
-
#applies?(_context) ⇒ Boolean
Always applies (catch-all rule).
-
#decide(context) ⇒ Object
Decision: Prefer prefix format when element_form_default is unqualified BUT: elementFormDefault only applies to LOCAL (nested) elements, not the root.
-
#priority ⇒ Object
Priority 5 - Lowest priority (catch-all).
Methods inherited from DecisionRule
Instance Method Details
#applies?(_context) ⇒ Boolean
Always applies (catch-all rule)
21 22 23 24 |
# File 'lib/lutaml/xml/decisions/rules/default_preference_rule.rb', line 21 def applies?(_context) # This rule always applies as the fallback true end |
#decide(context) ⇒ Object
Decision: Prefer prefix format when element_form_default is unqualified BUT: elementFormDefault only applies to LOCAL (nested) elements, not the root. The root element itself should use default format.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lutaml/xml/decisions/rules/default_preference_rule.rb', line 29 def decide(context) if context.has_namespace? ns_class = context.namespace_class # When element_form_default is EXPLICITLY set to unqualified AND this is NOT the root, # use prefix format so children can be in blank namespace (no xmlns). # Root element uses default format since elementFormDefault only affects local elements. # CRITICAL: Only applies when explicitly set, not when defaulted to :unqualified. if ns_class.element_form_default_set? && ns_class.element_form_default == :unqualified && !context.root? Decision.prefix( prefix: ns_class.prefix_default || "ns", namespace_class: ns_class, reason: "Priority 5: element_form_default :unqualified (non-root) - use prefix for parent", ) else Decision.default( namespace_class: ns_class, reason: "Priority 5: Default preference - use default format for cleaner output", ) end else # No namespace - no decision needed Decision.default( namespace_class: nil, reason: "Priority 5: No namespace - no prefix needed", ) end end |
#priority ⇒ Object
Priority 5 - Lowest priority (catch-all)
16 17 18 |
# File 'lib/lutaml/xml/decisions/rules/default_preference_rule.rb', line 16 def priority 5 end |