class Nokogiri::CSS::XPathVisitor - nokogiri-1.18.10 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`.

### Attributes

builtins[R]

The visitor configuration set via the `builtins:` keyword argument to `XPathVisitor.new`.

doctype[R]

The visitor configuration set via the `doctype:` keyword argument to `XPathVisitor.new`.

namespaces[R]

The visitor configuration set via the `namespaces:` keyword argument to `XPathVisitor.new`.

prefix[R]

The visitor configuration set via the `prefix:` keyword argument to `XPathVisitor.new`.

### 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 69
    def initialize(
      builtins: BuiltinsConfig::NEVER,
      doctype: DoctypeConfig::XML,
      prefix: Nokogiri::XML::XPath::GLOBAL_SEARCH_PREFIX,
      namespaces: nil
    )
      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
      @prefix = prefix
      @namespaces = namespaces
    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 93
    def config
      { builtins: @builtins, doctype: @doctype, prefix: @prefix, namespaces: @namespaces }
    end