Class: Lutaml::Xml::Element
- Inherits:
-
Object
- Object
- Lutaml::Xml::Element
- Includes:
- Model::Liquefiable
- Defined in:
- lib/lutaml/xml/element.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace_prefix ⇒ Object
readonly
Returns the value of attribute namespace_prefix.
-
#namespace_uri ⇒ Object
readonly
Returns the value of attribute namespace_uri.
-
#node_type ⇒ Object
readonly
Returns the value of attribute node_type.
-
#text_content ⇒ Object
readonly
Returns the value of attribute text_content.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#cdata? ⇒ Boolean
Check if this is a CDATA section.
- #comment? ⇒ Boolean
-
#element? ⇒ Boolean
Check if this is a regular element.
- #element_tag ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(type, name, text_content: nil, node_type: nil, namespace_uri: nil, namespace_prefix: nil, attributes: nil) ⇒ Element
constructor
Create a new Element for order tracking.
- #processing_instruction? ⇒ Boolean
-
#text? ⇒ Boolean
Check if this is a text content node (not CDATA).
- #to_liquid ⇒ Object
Methods included from Model::Liquefiable
Constructor Details
#initialize(type, name, text_content: nil, node_type: nil, namespace_uri: nil, namespace_prefix: nil, attributes: nil) ⇒ Element
Create a new Element for order tracking
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lutaml/xml/element.rb', line 21 def initialize(type, name, text_content: nil, node_type: nil, namespace_uri: nil, namespace_prefix: nil, attributes: 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 @attributes = attributes&.freeze end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/lutaml/xml/element.rb', line 6 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/lutaml/xml/element.rb', line 6 def name @name end |
#namespace_prefix ⇒ Object (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_uri ⇒ Object (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_type ⇒ Object (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_content ⇒ Object (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 |
#type ⇒ Object (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
43 44 45 |
# File 'lib/lutaml/xml/element.rb', line 43 def cdata? @node_type == :cdata end |
#comment? ⇒ Boolean
56 57 58 |
# File 'lib/lutaml/xml/element.rb', line 56 def comment? @node_type == :comment end |
#element? ⇒ Boolean
Check if this is a regular element
48 49 50 |
# File 'lib/lutaml/xml/element.rb', line 48 def element? @node_type == :element end |
#element_tag ⇒ Object
60 61 62 |
# File 'lib/lutaml/xml/element.rb', line 60 def element_tag @name unless text? || cdata? || comment? || processing_instruction? end |
#eql?(other) ⇒ Boolean Also known as: ==
64 65 66 67 68 69 70 |
# File 'lib/lutaml/xml/element.rb', line 64 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 |
#processing_instruction? ⇒ Boolean
52 53 54 |
# File 'lib/lutaml/xml/element.rb', line 52 def processing_instruction? @node_type == :processing_instruction end |
#text? ⇒ Boolean
Check if this is a text content node (not CDATA)
38 39 40 |
# File 'lib/lutaml/xml/element.rb', line 38 def text? @node_type == :text end |
#to_liquid ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/lutaml/xml/element.rb', line 72 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 |