--- !ruby/object:RI::ClassDescription 
attributes: []

class_methods: 
- !ruby/object:RI::MethodSummary 
  name: for_class
- !ruby/object:RI::MethodSummary 
  name: for_id
- !ruby/object:RI::MethodSummary 
  name: new
comment: 
- !ruby/struct:SM::Flow::P 
  body: Selects HTML elements using CSS 2 selectors.
- !ruby/struct:SM::Flow::P 
  body: The <tt>Selector</tt> class uses CSS selector expressions to match and select HTML elements.
- !ruby/struct:SM::Flow::P 
  body: "For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  selector = HTML::Selector.new &quot;form.login[action=/login]&quot;\n"
- !ruby/struct:SM::Flow::P 
  body: creates a new selector that matches any <tt>form</tt> element with the class <tt>login</tt> and an attribute <tt>action</tt> with the value <tt>/login</tt>.
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Matching Elements
- !ruby/struct:SM::Flow::P 
  body: "Use the #match method to determine if an element matches the selector."
- !ruby/struct:SM::Flow::P 
  body: For simple selectors, the method returns an array with that element, or <tt>nil</tt> if the element does not match. For complex selectors (see below) the method returns an array with all matched elements, of <tt>nil</tt> if no match found.
- !ruby/struct:SM::Flow::P 
  body: "For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  if selector.match(element)\n    puts &quot;Element is a login form&quot;\n  end\n"
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Selecting Elements
- !ruby/struct:SM::Flow::P 
  body: "Use the #select method to select all matching elements starting with one element and going through all children in depth-first order."
- !ruby/struct:SM::Flow::P 
  body: This method returns an array of all matching elements, an empty array if no match is found
- !ruby/struct:SM::Flow::P 
  body: "For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  selector = HTML::Selector.new &quot;input[type=text]&quot;\n  matches = selector.select(element)\n  matches.each do |match|\n    puts &quot;Found text field with name #{match.attributes['name']}&quot;\n  end\n"
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Expressions
- !ruby/struct:SM::Flow::P 
  body: "Selectors can match elements using any of the following criteria:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name</tt> -- Match an element based on its name (tag name). For example, <tt>p</tt> to match a paragraph. You can use <tt>*</tt> to match any element.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>#id</tt> -- Match an element based on its identifier (the <tt>id</tt> attribute). For example, <tt>#page</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>.class</tt> -- Match an element based on its class name, all class names if more than one specified.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>[attr]</tt> -- Match an element that has the specified attribute.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>[attr=value]</tt> -- Match an element that has the specified attribute and value. (More operators are supported see below)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:pseudo-class</tt> -- Match an element based on a pseudo class, such as <tt>:nth-child</tt> and <tt>:empty</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:not(expr)</tt> -- Match an element that does not match the negation expression.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: When using a combination of the above, the element name comes first followed by identifier, class names, attributes, pseudo classes and negation in any order. Do not seprate these parts with spaces! Space separation is used for descendant selectors.
- !ruby/struct:SM::Flow::P 
  body: "For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  selector = HTML::Selector.new &quot;form.login[action=/login]&quot;\n"
- !ruby/struct:SM::Flow::P 
  body: The matched element must be of type <tt>form</tt> and have the class <tt>login</tt>. It may have other classes, but the class <tt>login</tt> is required to match. It must also have an attribute called <tt>action</tt> with the value <tt>/login</tt>.
- !ruby/struct:SM::Flow::P 
  body: "This selector will match the following element:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;form class=&quot;login form&quot; method=&quot;post&quot; action=&quot;/login&quot;&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "but will not match the element:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;form method=&quot;post&quot; action=&quot;/logout&quot;&gt;\n"
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Attribute Values
- !ruby/struct:SM::Flow::P 
  body: "Several operators are supported for matching attributes:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name</tt> -- The element must have an attribute with that name.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name=value</tt> -- The element must have an attribute with that name and value.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name^=value</tt> -- The attribute value must start with the specified value.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name$=value</tt> -- The attribute value must end with the specified value.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name*=value</tt> -- The attribute value must contain the specified value.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name~=word</tt> -- The attribute value must contain the specified word (space separated).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>name|=word</tt> -- The attribute value must start with specified word.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "For example, the following two selectors match the same element:"
- !ruby/struct:SM::Flow::VERB 
  body: "  #my_id\n  [id=my_id]\n"
- !ruby/struct:SM::Flow::P 
  body: "and so do the following two selectors:"
- !ruby/struct:SM::Flow::VERB 
  body: "  .my_class\n  [class~=my_class]\n"
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Alternatives, siblings, children
- !ruby/struct:SM::Flow::P 
  body: "Complex selectors use a combination of expressions to match elements:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>expr1 expr2</tt> -- Match any element against the second expression if it has some parent element that matches the first expression.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>expr1 &gt; expr2</tt> -- Match any element against the second expression if it is the child of an element that matches the first expression.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>expr1 + expr2</tt> -- Match any element against the second expression if it immediately follows an element that matches the first expression.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>expr1 ~ expr2</tt> -- Match any element against the second expression that comes after an element that matches the first expression.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>expr1, expr2</tt> -- Match any element against the first expression, or against the second expression.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "Since children and sibling selectors may match more than one element given the first element, the #match method may return more than one match."
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Pseudo classes
- !ruby/struct:SM::Flow::P 
  body: "Pseudo classes were introduced in CSS 3. They are most often used to select elements in a given position:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:root</tt> -- Match the element only if it is the root element (no parent element).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:empty</tt> -- Match the element only if it has no child elements, and no text content.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:only-child</tt> -- Match the element if it is the only child (element) of its parent element.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:only-of-type</tt> -- Match the element if it is the only child (element) of its parent element and its type.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:first-child</tt> -- Match the element if it is the first child (element) of its parent element.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:first-of-type</tt> -- Match the element if it is the first child (element) of its parent element of its type.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:last-child</tt> -- Match the element if it is the last child (element) of its parent element.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:last-of-type</tt> -- Match the element if it is the last child (element) of its parent element of its type.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-child(b)</tt> -- Match the element if it is the b-th child (element) of its parent element. The value <tt>b</tt> specifies its index, starting with 1.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-child(an+b)</tt> -- Match the element if it is the b-th child (element) in each group of <tt>a</tt> child elements of its parent element.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-child(-an+b)</tt> -- Match the element if it is the first child (element) in each group of <tt>a</tt> child elements, up to the first <tt>b</tt> child elements of its parent element.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-child(odd)</tt> -- Match element in the odd position (i.e. first, third). Same as <tt>:nth-child(2n+1)</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-child(even)</tt> -- Match element in the even position (i.e. second, fourth). Same as <tt>:nth-child(2n+2)</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-of-type(..)</tt> -- As above, but only counts elements of its type.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-last-child(..)</tt> -- As above, but counts from the last child.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:nth-last-of-type(..)</tt> -- As above, but counts from the last child and only elements of its type.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:not(selector)</tt> -- Match the element only if the element does not match the simple selector.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: As you can see, &lt;tt&gt;:nth-child&lt;tt&gt; pseudo class and its varient can get quite tricky and the CSS specification doesn't do a much better job explaining it. But after reading the examples and trying a few combinations, it's easy to figure out.
- !ruby/struct:SM::Flow::P 
  body: "For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  table tr:nth-child(odd)\n"
- !ruby/struct:SM::Flow::P 
  body: Selects every second row in the table starting with the first one.
- !ruby/struct:SM::Flow::VERB 
  body: "  div p:nth-child(4)\n"
- !ruby/struct:SM::Flow::P 
  body: Selects the fourth paragraph in the <tt>div</tt>, but not if the <tt>div</tt> contains other elements, since those are also counted.
- !ruby/struct:SM::Flow::VERB 
  body: "  div p:nth-of-type(4)\n"
- !ruby/struct:SM::Flow::P 
  body: Selects the fourth paragraph in the <tt>div</tt>, counting only paragraphs, and ignoring all other elements.
- !ruby/struct:SM::Flow::VERB 
  body: "  div p:nth-of-type(-n+4)\n"
- !ruby/struct:SM::Flow::P 
  body: Selects the first four paragraphs, ignoring all others.
- !ruby/struct:SM::Flow::P 
  body: "And you can always select an element that matches one set of rules but not another using <tt>:not</tt>. For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  p:not(.post)\n"
- !ruby/struct:SM::Flow::P 
  body: Matches all paragraphs that do not have the class <tt>.post</tt>.
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Substitution Values
- !ruby/struct:SM::Flow::P 
  body: You can use substitution with identifiers, class names and element values. A substitution takes the form of a question mark (<tt>?</tt>) and uses the next value in the argument list following the CSS expression.
- !ruby/struct:SM::Flow::P 
  body: The substitution value may be a string or a regular expression. All other values are converted to strings.
- !ruby/struct:SM::Flow::P 
  body: "For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  selector = HTML::Selector.new &quot;#?&quot;, /^\\d+$/\n"
- !ruby/struct:SM::Flow::P 
  body: matches any element whose identifier consists of one or more digits.
- !ruby/struct:SM::Flow::P 
  body: See http://www.w3.org/TR/css3-selectors/
constants: []

full_name: HTML::Selector
includes: []

instance_methods: 
- !ruby/object:RI::MethodSummary 
  name: attribute_match
- !ruby/object:RI::MethodSummary 
  name: match
- !ruby/object:RI::MethodSummary 
  name: next_element
- !ruby/object:RI::MethodSummary 
  name: next_selector
- !ruby/object:RI::MethodSummary 
  name: nth_child
- !ruby/object:RI::MethodSummary 
  name: only_child
- !ruby/object:RI::MethodSummary 
  name: select
- !ruby/object:RI::MethodSummary 
  name: select_first
- !ruby/object:RI::MethodSummary 
  name: simple_selector
name: Selector
superclass: Object
