Module: Hexp::Node::Children
- Included in:
- Hexp::Node
- Defined in:
- lib/hexp/node/children.rb
Overview
Node API methods that deal with child_nodes
Instance Method Summary collapse
-
#add_child(child) ⇒ Hexp::Node
(also: #add, #<<)
Add a child node to the end of the list of children.
- #append(*nodes) ⇒ Object
-
#content(*args) ⇒ Hexp::Node
(also: #set_children)
Replace the children of this node with a new list of children.
-
#empty? ⇒ true, false
Is this node an empty node.
-
#map_children {|The| ... } ⇒ Hexp::Node
Perform an action on each child node, and replace the node with the result.
-
#text ⇒ String
All the text in this node and its descendants.
Instance Method Details
#add_child(child) ⇒ Hexp::Node Also known as: add, <<
Add a child node to the end of the list of children
32 33 34 35 36 37 38 |
# File 'lib/hexp/node/children.rb', line 32 def add_child(child) H[ self.tag, self.attributes, self.children + [child] ] end |
#append(*nodes) ⇒ Object
99 100 101 |
# File 'lib/hexp/node/children.rb', line 99 def append(*nodes) H[tag, attributes, children + nodes] end |
#content(*args) ⇒ Hexp::Node Also known as: set_children
Replace the children of this node with a new list of children
75 76 77 |
# File 'lib/hexp/node/children.rb', line 75 def content(*args) H[tag, attributes, *args] end |
#empty? ⇒ true, false
Is this node an empty node
16 17 18 |
# File 'lib/hexp/node/children.rb', line 16 def empty? children.empty? end |
#map_children {|The| ... } ⇒ Hexp::Node
Perform an action on each child node, and replace the node with the result
94 95 96 97 |
# File 'lib/hexp/node/children.rb', line 94 def map_children(&blk) return to_enum(:map_children) unless block_given? H[tag, attributes, children.map(&blk)] end |
#text ⇒ String
All the text in this node and its descendants
Concatenates the contents of all text nodes.
58 59 60 61 62 |
# File 'lib/hexp/node/children.rb', line 58 def text children.map do |node| node.text? ? node : node.text end.join end |