Class: Lutaml::Xml::Decisions::Rules::ExplicitOptionRule

Inherits:
DecisionRule
  • Object
show all
Defined in:
lib/lutaml/xml/decisions/rules/explicit_option_rule.rb

Overview

Priority 0.75: Explicit prefix option

User explicitly specified prefix option (true, false, or custom string) CRITICAL: This MUST override FormatPreservationRule (Priority 1) to allow users to override preserved input format during serialization. Example: parse default, serialize prefixed (cross-parse)

Instance Method Summary collapse

Methods inherited from DecisionRule

#<=>, #name

Instance Method Details

#applies?(context) ⇒ Boolean

Applies when explicit prefix option is set

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/lutaml/xml/decisions/rules/explicit_option_rule.rb', line 21

def applies?(context)
  return false unless context.has_namespace?

  !context.explicit_prefix_option.nil?
end

#decide(context) ⇒ Object

Decision: Use the explicit option value



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lutaml/xml/decisions/rules/explicit_option_rule.rb', line 28

def decide(context)
  option = context.explicit_prefix_option

  if option.is_a?(String)
    # Custom prefix string
    Decision.prefix(
      prefix: option,
      namespace_class: context.namespace_class,
      reason: "Priority 2: Explicit prefix option (custom string)",
    )
  elsif option == true
    # Force prefix format
    Decision.prefix(
      prefix: context.namespace_class.prefix_default,
      namespace_class: context.namespace_class,
      reason: "Priority 2: Explicit prefix option (true)",
    )
  else
    # Force default format (option == false)
    Decision.default(
      namespace_class: context.namespace_class,
      reason: "Priority 2: Explicit prefix option (false)",
    )
  end
end

#priorityObject

Priority 0.75 - Higher than FormatPreservationRule (1)



16
17
18
# File 'lib/lutaml/xml/decisions/rules/explicit_option_rule.rb', line 16

def priority
  0.75
end