public Method

Selector.select_first(root)

Similar to #select but returns the first matching element. Returns nil if no element matches the selector.

Source Code

# File 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
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.