protected Method

Selector.only_child(of_type)

Creates a only child lambda. Pass +of-type+ to only look at elements of its type.

Source Code

# File action_controller/vendor/html-scanner/html/selector.rb, line 772
def only_child(of_type)
  lambda do |element|
    # Element must be inside parent element.
    return false unless element.parent && element.parent.tag?
    name = of_type ? element.name : nil
    other = false
    for child in element.parent.children
      # Skip text nodes/comments.
      if child.tag? && (name == nil || child.name == name)
        unless child.equal?(element)
          other = true
          break
        end
      end
    end
    !other
  end
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.