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?, #parse_errors, #parse_errors=

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.



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

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

Instance Attribute Details

#originalObject

Returns the value of attribute original.



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

def original
  @original
end

#valueObject

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



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

def name
  "#text"
end

#node_typeObject



34
35
36
# File 'lib/canon/xml/nodes/text_node.rb', line 34

def node_type
  :text
end

#text_contentObject



38
39
40
# File 'lib/canon/xml/nodes/text_node.rb', line 38

def text_content
  @value
end