Class: Lutaml::Xml::Element

Inherits:
Object
  • Object
show all
Includes:
Model::Liquefiable
Defined in:
lib/lutaml/xml/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Model::Liquefiable

included

Constructor Details

#initialize(type, name, text_content: nil, node_type: nil, namespace_uri: nil, namespace_prefix: nil) ⇒ Element

Create a new Element for order tracking

Parameters:

  • type (String)

    “Text” or “Element” (deprecated, use node_type)

  • name (String)

    The element name or text marker

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

    Actual text content for text nodes

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

    The node type (:text, :cdata, :element, :comment)

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

    The namespace URI of this element

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

    The namespace prefix of this element



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lutaml/xml/element.rb', line 17

def initialize(type, name, text_content: nil, node_type: nil,
               namespace_uri: nil, namespace_prefix: nil)
  @type = type # "Text" or "Element" - deprecated, kept for backward compatibility
  @name = name
  # Infer node_type from type for backward compatibility if not provided
  @node_type = node_type || infer_node_type(type, name)
  # For text nodes, store both marker ("text") and actual content.
  # Regular element-order entries do not carry text content.
  @text_content = text_content
  @text_content ||= name if text? || cdata?
  @namespace_uri = namespace_uri
  @namespace_prefix = namespace_prefix
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/lutaml/xml/element.rb', line 6

def name
  @name
end

#namespace_prefixObject (readonly)

Returns the value of attribute namespace_prefix.



6
7
8
# File 'lib/lutaml/xml/element.rb', line 6

def namespace_prefix
  @namespace_prefix
end

#namespace_uriObject (readonly)

Returns the value of attribute namespace_uri.



6
7
8
# File 'lib/lutaml/xml/element.rb', line 6

def namespace_uri
  @namespace_uri
end

#node_typeObject (readonly)

Returns the value of attribute node_type.



6
7
8
# File 'lib/lutaml/xml/element.rb', line 6

def node_type
  @node_type
end

#text_contentObject (readonly)

Returns the value of attribute text_content.



6
7
8
# File 'lib/lutaml/xml/element.rb', line 6

def text_content
  @text_content
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/lutaml/xml/element.rb', line 6

def type
  @type
end

Instance Method Details

#cdata?Boolean

Check if this is a CDATA section

Returns:

  • (Boolean)


37
38
39
# File 'lib/lutaml/xml/element.rb', line 37

def cdata?
  @node_type == :cdata
end

#element?Boolean

Check if this is a regular element

Returns:

  • (Boolean)


42
43
44
# File 'lib/lutaml/xml/element.rb', line 42

def element?
  @node_type == :element
end

#element_tagObject



46
47
48
# File 'lib/lutaml/xml/element.rb', line 46

def element_tag
  @name unless text? || cdata?
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/lutaml/xml/element.rb', line 50

def eql?(other)
  return false unless other.is_a?(self.class)

  # Only compare type and name for backward compatibility
  # text_content is for internal round-trip use only
  @type == other.type && @name == other.name
end

#text?Boolean

Check if this is a text content node (not CDATA)

Returns:

  • (Boolean)


32
33
34
# File 'lib/lutaml/xml/element.rb', line 32

def text?
  @node_type == :text
end

#to_liquidObject



58
59
60
61
62
63
64
# File 'lib/lutaml/xml/element.rb', line 58

def to_liquid
  self.class.validate_liquid!
  self.class.register_liquid_drop_class unless self.class.drop_class

  register_liquid_methods
  self.class.drop_class.new(self)
end