Class: Polites::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/polites/node.rb

Overview

The Node is the basic building block of the AST we parse Polites document contents into.

Direct Known Subclasses

Block, Span

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(children = []) ⇒ Node

Returns a new instance of Node.

Parameters:

  • children (Array<Node>) (defaults to: [])


11
12
13
# File 'lib/polites/node.rb', line 11

def initialize(children = [])
  @children = children
end

Instance Attribute Details

#childrenArray<Node> (readonly)

Returns:



8
9
10
# File 'lib/polites/node.rb', line 8

def children
  @children
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


22
23
24
# File 'lib/polites/node.rb', line 22

def eql?(other)
  other.is_a?(self.class) && children.eql?(other.children)
end

#textString

Assemble the text contents of this node and all its children combined.

Returns:

  • (String)


18
19
20
# File 'lib/polites/node.rb', line 18

def text
  @children.map(&:text).join
end