class Nokogiri::CSS::XPathVisitor - nokogiri-1.15.2 Documentation

# class Nokogiri::CSS::XPathVisitor

When translating `CSS` selectors to XPath queries with `Nokogiri::CSS.xpath_for`, the `XPathVisitor` class allows for changing some of the behaviors related to builtin xpath functions and quirks of `HTML5`.

### Public Class Methods

new() → XPathVisitor click to toggle source
new(builtins:, doctype:) → XPathVisitor

Parameters

- `builtins:` (`BuiltinsConfig`) Determine when to use Nokogiri’s built-in xpath functions for performance improvements.

- `doctype:` (`DoctypeConfig`) Make document-type-specific accommodations for `CSS` queries.

Returns

  `XPathVisitor`

    # File lib/nokogiri/css/xpath_visitor.rb, line 57
    def initialize(builtins: BuiltinsConfig::NEVER, doctype: DoctypeConfig::XML)
      unless BuiltinsConfig::VALUES.include?(builtins)
        raise(ArgumentError, "Invalid values #{builtins.inspect} for builtins: keyword parameter")
      end
      unless DoctypeConfig::VALUES.include?(doctype)
        raise(ArgumentError, "Invalid values #{doctype.inspect} for doctype: keyword parameter")
      end

      @builtins = builtins
      @doctype = doctype
    end

### Public Instance Methods

config() → Hash click to toggle source

Returns

  a Hash representing the configuration of the `XPathVisitor`, suitable for use as part of the `CSS` cache key.

    # File lib/nokogiri/css/xpath_visitor.rb, line 74
    def config
      { builtins: @builtins, doctype: @doctype }
    end