DecodeSourceDecodeCommentNode

class Node

Definitions

def initialize(children = nil)

Initialize the node.

Signature

parameter children Array(Node) | Nil

Implementation

def initialize(children = nil)
	@children = children
end

def children?

Whether this node has any children nodes. Ignores class Decode::Comment::Text instances.

Signature

returns Boolean

Implementation

def children?
	@children&.any?{|child| child.is_a?(Node)}
end

def add(child)

Add a child node to this node.

Signature

parameter child Node

The node to add.

Implementation

def add(child)
	@children ||= []
	@children << child
end

attr :children

Any children of this node.

Signature

attribute Array(Node | Text) | Nil

def each(&block)

Enumerate all non-text children nodes.

Implementation

def each(&block)
	return to_enum unless block_given?
	
	@children&.each do |child|
		yield child if child.is_a?(Node)
	end
end

def text

Any lines of text associated with this node.

Signature

returns Array(String) | Nil

The lines of text.

Implementation

def text
	if text = self.extract_text
		return text if text.any?
	end
end

def traverse(&block)

Traverse the tags from this node using Decode::Comment::Node#each. Invoke descend.call(child) to recursively traverse the specified child.

Signature

yields {|node, descend| descend.call}
parameter node Node

The current node which is being traversed.

parameter descend Proc | Nil

The recursive method for traversing children.

Implementation

def traverse(&block)
	descend = ->(node){
		node.traverse(&block)
	}
	
	yield(self, descend)
end