new

Selector.new(string, [values ...]) => selector Class Public methods Creates a new selector from a CSS 2 selector expression. The first argument is the selector expression. All other arguments are used for value substitution. Throws InvalidSelectorError is the selector expression is invalid.

match

match(element, first?) => array or nil Instance Public methods Matches an element against the selector. For a simple selector this method returns an array with the element if the element matches, nil otherwise. For a complex selector (sibling and descendant) this method returns an array with all matching elements, nil if no match is found. Use +first_only=true+ if you are only interested in the first element. For example: if selector.match(element) puts "Element is a login fo

next_element

next_element(element, name = nil) Instance Public methods Returns the next element after this one. Skips sibling text nodes. With the name argument, returns the next element with that name, skipping other sibling elements.

select

select(root) => array Instance Public methods Selects and returns an array with all matching elements, beginning with one node and traversing through all children depth-first. Returns an empty array if no match is found. The root node may be any element in the document, or the document itself. For example: selector = HTML::Selector.new "input[type=text]" matches = selector.select(element) matches.each do |match| puts "Found text field with name #{match.attributes['name']}" en

select_first

select_first(root) Instance Public methods Similar to select but returns the first matching element. Returns nil if no element matches the selector.

attribute_match

attribute_match(equality, value) Instance Protected methods Create a regular expression to match an attribute value based on the equality operator (=, ^=, |=, etc).

next_selector

next_selector(statement, values) Instance Protected methods Called to create a dependent selector (sibling, descendant, etc). Passes the remainder of the statement that will be reduced to zero eventually, and array of substitution values. This method is called from four places, so it helps to put it here for reuse. The only logic deals with the need to detect comma separators (alternate) and apply them to the selector group of the top selector.

nth_child

nth_child(a, b, of_type, reverse) Instance Protected methods Returns a lambda that can match an element against the nth-child pseudo class, given the following arguments: a â Value of a part. b â Value of b part. of_type â True to test only elements of this type (of-type). reverse â True to count in reverse order (last-).

only_child

only_child(of_type) Instance Protected methods Creates a only child lambda. Pass of-type to only look at elements of its type.

simple_selector

simple_selector(statement, values, can_negate = true) Instance Protected methods Creates a simple selector given the statement and array of substitution values. Returns a hash with the values tag_name, attributes, pseudo (classes) and negation. Called the first time with can_negate true to allow negation. Called a second time with false since negation cannot be negated.