Method: HTML::Selector#select_first
- Defined in:
- lib/action_controller/vendor/html-scanner/html/selector.rb
#select_first(root) ⇒ Object
Similar to #select but returns the first matching element. Returns nil if no element matches the selector.
471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/action_controller/vendor/html-scanner/html/selector.rb', line 471 def select_first(root) stack = [root] while node = stack.pop if node.tag? && subset = match(node, true) return subset.first if !subset.empty? elsif children = node.children stack.concat children.reverse end end nil end |