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)
- - (Object) add_child(child) (also: #add, #<<)
-
- (Boolean) empty?
Is this node an empty node.
- - (Object) map_children(&blk)
- - (Object) set_children(new_children)
- - (Object) text
Instance Method Details
- (Object) add_child(child) Also known as: add, <<
18 19 20 21 22 23 24 |
# File 'lib/hexp/node/children.rb', line 18 def add_child(child) H[ self.tag, self.attributes, self.children + [child] ] end |
- (Boolean) empty?
Is this node an empty node
H[:p, class: 'foo'].empty? #=> true H[:p, [H].empty? #=> false
14 15 16 |
# File 'lib/hexp/node/children.rb', line 14 def empty? children.empty? end |
- (Object) map_children(&blk)
38 39 40 41 |
# File 'lib/hexp/node/children.rb', line 38 def map_children(&blk) return to_enum(:map_children) unless block_given? H[tag, attributes, children.map(&blk)] end |
- (Object) set_children(new_children)
34 35 36 |
# File 'lib/hexp/node/children.rb', line 34 def set_children(new_children) H[tag, attributes, new_children] end |
- (Object) text
28 29 30 31 32 |
# File 'lib/hexp/node/children.rb', line 28 def text children.map do |node| node.text? ? node : node.text end.join end |