Class: SyntaxTree::XML::Document

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/xml/nodes.rb

Overview

The Document node is the top of the syntax tree. It contains an optional prolog, an optional doctype declaration, any number of optional miscellenous elements like comments, whitespace, or processing instructions, and a root element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#format, #pretty_print

Constructor Details

#initialize(prolog:, miscs:, doctype:, element:, location:) ⇒ Document

Returns a new instance of Document.



84
85
86
87
88
89
90
# File 'lib/syntax_tree/xml/nodes.rb', line 84

def initialize(prolog:, miscs:, doctype:, element:, location:)
  @prolog = prolog
  @miscs = miscs
  @doctype = doctype
  @element = element
  @location = location
end

Instance Attribute Details

#doctypeObject (readonly)

Returns the value of attribute doctype.



82
83
84
# File 'lib/syntax_tree/xml/nodes.rb', line 82

def doctype
  @doctype
end

#elementObject (readonly)

Returns the value of attribute element.



82
83
84
# File 'lib/syntax_tree/xml/nodes.rb', line 82

def element
  @element
end

#locationObject (readonly)

Returns the value of attribute location.



82
83
84
# File 'lib/syntax_tree/xml/nodes.rb', line 82

def location
  @location
end

#miscsObject (readonly)

Returns the value of attribute miscs.



82
83
84
# File 'lib/syntax_tree/xml/nodes.rb', line 82

def miscs
  @miscs
end

#prologObject (readonly)

Returns the value of attribute prolog.



82
83
84
# File 'lib/syntax_tree/xml/nodes.rb', line 82

def prolog
  @prolog
end

Instance Method Details

#accept(visitor) ⇒ Object



92
93
94
# File 'lib/syntax_tree/xml/nodes.rb', line 92

def accept(visitor)
  visitor.visit_document(self)
end

#child_nodesObject Also known as: deconstruct



96
97
98
# File 'lib/syntax_tree/xml/nodes.rb', line 96

def child_nodes
  [prolog, *miscs, doctype, element].compact
end

#deconstruct_keys(keys) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/syntax_tree/xml/nodes.rb', line 102

def deconstruct_keys(keys)
  {
    prolog: prolog,
    miscs: miscs,
    doctype: doctype,
    element: element,
    location: location
  }
end