Class: Brandish::Parser::Node::Root
- Inherits:
-
Brandish::Parser::Node
- Object
- Brandish::Parser::Node
- Brandish::Parser::Node::Root
- Defined in:
- lib/brandish/parser/node/root.rb
Overview
The root node. This is the parent of the full document.
Instance Attribute Summary collapse
-
#children ⇒ <Node>
readonly
The children of the root node.
Attributes inherited from Brandish::Parser::Node
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks for equivalence between this and another object.
-
#flatten ⇒ ::String
This flattens out the root node into a single string value.
-
#initialize(children:, location: nil) ⇒ Root
constructor
Initialize the root node with the given children and location.
-
#inspect ⇒ ::String
Pretty inspect.
Methods inherited from Brandish::Parser::Node
#prevent_update, #update, #update_prevented?
Constructor Details
#initialize(children:, location: nil) ⇒ Root
Initialize the root node with the given children and location.
21 22 23 24 25 26 |
# File 'lib/brandish/parser/node/root.rb', line 21 def initialize(children:, location: nil) @children = children.freeze @location = location || derive_location(children) fail unless children.any? freeze end |
Instance Attribute Details
#children ⇒ <Node> (readonly)
The children of the root node. This should be a series of nodes that are in the body.
13 14 15 |
# File 'lib/brandish/parser/node/root.rb', line 13 def children @children end |
Instance Method Details
#==(other) ⇒ Boolean
Checks for equivalence between this and another object. If the other object is this object, it returns true; otherwise, if the other object is a root, and its properties are equal to this one, it returns true; otherwise, it returns false.
43 44 45 46 |
# File 'lib/brandish/parser/node/root.rb', line 43 def ==(other) equal?(other) || other.is_a?(Root) && @children == other.children && @location == other.location end |
#flatten ⇒ ::String
This flattens out the root node into a single string value. This is used for outputing the contents.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/brandish/parser/node/root.rb', line 53 def flatten children.map do |child| case child when Node::Root then child.flatten when Node::Text then child.value else fail NodeError.new("Unexpected node `#{child.class}", node.location) end end.join end |
#inspect ⇒ ::String
Pretty inspect.
31 32 33 34 |
# File 'lib/brandish/parser/node/root.rb', line 31 def inspect "#<#{self.class} children=#{@children.inspect} " \ "location=#{@location.inspect}>" end |