Class: Hexp::Node::Selector
- Inherits:
-
Object
- Object
- Hexp::Node::Selector
- Includes:
- Enumerable
- Defined in:
- lib/hexp/node/selector.rb
Overview
Direct Known Subclasses
Instance Method Summary (collapse)
- - (Object) attr(name, value)
- - (Object) each {|@node| ... }
-
- (Selector) initialize(node, block)
constructor
A new instance of Selector.
- - (Object) rewrite(&block)
- - (Object) wrap(tag, attributes = {})
Constructor Details
- (Selector) initialize(node, block)
A new instance of Selector
23 24 25 |
# File 'lib/hexp/node/selector.rb', line 23 def initialize(node, block) @node, @select_block = node, block end |
Instance Method Details
- (Object) attr(name, value)
37 38 39 40 41 |
# File 'lib/hexp/node/selector.rb', line 37 def attr(name, value) rewrite do |node| node.attr(name, value) end end |
- (Object) each {|@node| ... }
49 50 51 52 53 54 55 56 |
# File 'lib/hexp/node/selector.rb', line 49 def each(&block) return to_enum(:each) unless block_given? @node.children.each do |child| child.select(&@select_block).each(&block) end yield @node if @select_block.(@node) end |
- (Object) rewrite(&block)
27 28 29 30 31 32 33 34 35 |
# File 'lib/hexp/node/selector.rb', line 27 def rewrite(&block) @node.rewrite do |node, parent| if @select_block.(node) block.(node, parent) else node end end end |
- (Object) wrap(tag, attributes = {})
43 44 45 46 47 |
# File 'lib/hexp/node/selector.rb', line 43 def wrap(tag, attributes = {}) rewrite do |node| H[tag, attributes, [node]] end end |