Class: AsciidoctorVaped::AST::Node
- Inherits:
-
Object
- Object
- AsciidoctorVaped::AST::Node
- Defined in:
- lib/asciidoctor_vaped/ast/node.rb
Constant Summary collapse
- TEXT_CONTEXTS =
%i[text link strong emphasis monospace].freeze
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #<<(node) ⇒ Object
- #append(node) ⇒ Object
- #append_children(nodes) ⇒ Object
-
#initialize(children: []) ⇒ Node
constructor
A new instance of Node.
- #parse_inline ⇒ Object
- #sections ⇒ Object
- #text ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(children: []) ⇒ Node
Returns a new instance of Node.
11 12 13 14 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 11 def initialize(children: []) @children = [] append_children(children) end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 8 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 9 def parent @parent end |
Instance Method Details
#<<(node) ⇒ Object
16 17 18 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 16 def <<(node) append(node) end |
#append(node) ⇒ Object
20 21 22 23 24 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 20 def append(node) node.parent = self children << node node end |
#append_children(nodes) ⇒ Object
26 27 28 29 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 26 def append_children(nodes) nodes.each { |node| append(node) } self end |
#parse_inline ⇒ Object
35 36 37 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 35 def parse_inline append_children(Parser::Inline.parse(text)) end |
#sections ⇒ Object
39 40 41 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 39 def sections children.select { |child| child.context == :section } end |
#text ⇒ Object
31 32 33 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 31 def text children.select { |child| TEXT_CONTEXTS.include?(child.context) }.map(&:text).join end |
#to_h ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/asciidoctor_vaped/ast/node.rb', line 43 def to_h { context:, text:, attributes:, children: children.map(&:to_h) } end |