Class: Lutaml::Xml::Element
- Inherits:
-
Object
- Object
- Lutaml::Xml::Element
- Includes:
- Model::Liquefiable
- Defined in:
- lib/lutaml/xml/element.rb
Instance Attribute Summary collapse
-
#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.
-
#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) ⇒ Element
constructor
Create a new Element for order tracking.
-
#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) ⇒ Element
Create a new Element for order tracking
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
#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
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
42 43 44 |
# File 'lib/lutaml/xml/element.rb', line 42 def element? @node_type == :element end |
#element_tag ⇒ Object
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: ==
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)
32 33 34 |
# File 'lib/lutaml/xml/element.rb', line 32 def text? @node_type == :text end |
#to_liquid ⇒ Object
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 |