Class: Lutaml::Xml::Decisions::ElementPrefixResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/decisions/element_prefix_resolver.rb

Overview

Element Prefix Resolver - Determines element namespace format

This is the main public API for element namespace decisions. Replaces the procedural determine_element_prefix method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine = DecisionEngine.default) ⇒ ElementPrefixResolver

Returns a new instance of ElementPrefixResolver.



14
15
16
17
# File 'lib/lutaml/xml/decisions/element_prefix_resolver.rb', line 14

def initialize(engine = DecisionEngine.default)
  @engine = engine
  freeze
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine.



12
13
14
# File 'lib/lutaml/xml/decisions/element_prefix_resolver.rb', line 12

def engine
  @engine
end

Instance Method Details

#resolve(xml_element, mapping, needs, options, is_root: false, parent_format: nil, parent_namespace_class: nil, parent_namespace_prefix: nil, parent_hoisted: {}) ⇒ String?

Resolve the prefix decision for an element

Parameters:

  • xml_element (XmlDataModel::XmlElement)

    The element

  • mapping (Xml::Mapping)

    The mapping

  • needs (NamespaceNeeds)

    Namespace needs

  • options (Hash)

    Serialization options

  • is_root (Boolean) (defaults to: false)

    Whether this is the root element

  • parent_format (Symbol, nil) (defaults to: nil)

    Parent’s format (:prefix or :default)

  • parent_namespace_class (Class, nil) (defaults to: nil)

    Parent’s namespace class

  • parent_namespace_prefix (String, nil) (defaults to: nil)

    Parent’s actual namespace prefix (nil if default format)

  • parent_hoisted (Hash) (defaults to: {})

    Namespaces hoisted on parent => uri

Returns:

  • (String, nil)

    The prefix to use, or nil for default format



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
# File 'lib/lutaml/xml/decisions/element_prefix_resolver.rb', line 31

def resolve(xml_element, mapping, needs, options,
           is_root: false,
           parent_format: nil,
           parent_namespace_class: nil,
           parent_namespace_prefix: nil,
           parent_hoisted: {})
  # Create decision context
  context = DecisionContext.new(
    element: xml_element,
    mapping: mapping,
    needs: needs,
    options: options,
    is_root: is_root,
    parent_format: parent_format,
    parent_namespace_class: parent_namespace_class,
    parent_namespace_prefix: parent_namespace_prefix,
    parent_hoisted: parent_hoisted,
  )

  # Execute decision engine
  decision = @engine.execute(context)

  # Return prefix (or nil for default format)
  decision.prefix
end

#resolve_with_decision(xml_element, mapping, needs, options, is_root: false, parent_format: nil, parent_namespace_class: nil, parent_namespace_prefix: nil, parent_hoisted: {}, element_used_prefix: nil) ⇒ Decision

Resolve with full decision details (for debugging/logging)

Returns:

  • (Decision)

    The full decision object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/lutaml/xml/decisions/element_prefix_resolver.rb', line 60

def resolve_with_decision(xml_element, mapping, needs, options,
                         is_root: false,
                         parent_format: nil,
                         parent_namespace_class: nil,
                         parent_namespace_prefix: nil,
                         parent_hoisted: {},
                         element_used_prefix: nil)
  context = DecisionContext.new(
    element: xml_element,
    mapping: mapping,
    needs: needs,
    options: options,
    is_root: is_root,
    parent_format: parent_format,
    parent_namespace_class: parent_namespace_class,
    parent_namespace_prefix: parent_namespace_prefix,
    parent_hoisted: parent_hoisted,
    element_used_prefix: element_used_prefix,
  )

  @engine.execute(context)
end