Class: Canon::Xml::Nodes::TextNode

Inherits:
Canon::Xml::Node show all
Defined in:
lib/canon/xml/nodes/text_node.rb

Overview

Text node in the XPath data model

Stores both the decoded text value and the original text (with entity references preserved) to enable accurate round-trip serialization.

Instance Attribute Summary collapse

Attributes inherited from Canon::Xml::Node

#children, #parent

Instance Method Summary collapse

Methods inherited from Canon::Xml::Node

#add_child, #in_node_set=, #in_node_set?

Constructor Details

#initialize(value:, original: nil) ⇒ TextNode

Returns a new instance of TextNode.

Parameters:

  • value (String)

    Decoded text content (entity references resolved)

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

    Original text as it appeared in source XML, with entity references preserved (e.g., ““” instead of ‘“’). If not provided, defaults to value.



19
20
21
22
23
# File 'lib/canon/xml/nodes/text_node.rb', line 19

def initialize(value:, original: nil)
  super()
  @value = value
  @original = original || value
end

Instance Attribute Details

#originalObject (readonly)

Returns the value of attribute original.



13
14
15
# File 'lib/canon/xml/nodes/text_node.rb', line 13

def original
  @original
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'lib/canon/xml/nodes/text_node.rb', line 13

def value
  @value
end

Instance Method Details

#nameObject



25
26
27
# File 'lib/canon/xml/nodes/text_node.rb', line 25

def name
  "#text"
end

#node_typeObject



29
30
31
# File 'lib/canon/xml/nodes/text_node.rb', line 29

def node_type
  :text
end