instance method attribute_match

Ruby on Rails 4.0.13

Since v2.2.3 Last seen in v4.1.16

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16

Signature

attribute_match(equality, value)

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

Parameters

equality req
value req
Source
# File actionpack/lib/action_view/vendor/html-scanner/html/selector.rb, line 689
    def attribute_match(equality, value)
      regexp = value.is_a?(Regexp) ? value : Regexp.escape(value.to_s)
      case equality
        when "=" then
          # Match the attribute value in full
          Regexp.new("^#{regexp}$")
        when "~=" then
          # Match a space-separated word within the attribute value
          Regexp.new("(^|\s)#{regexp}($|\s)")
        when "^="
          # Match the beginning of the attribute value
          Regexp.new("^#{regexp}")
        when "$="
          # Match the end of the attribute value
          Regexp.new("#{regexp}$")
        when "*="
          # Match substring of the attribute value
          regexp.is_a?(Regexp) ? regexp : Regexp.new(regexp)
        when "|=" then
          # Match the first space-separated item of the attribute value
          Regexp.new("^#{regexp}($|\s)")
        else
          raise InvalidSelectorError, "Invalid operation/value" unless value.empty?
          # Match all attributes values (existence check)
          //
      end
    end

Defined in actionpack/lib/action_view/vendor/html-scanner/html/selector.rb line 689 · View on GitHub · Improve this page · Find usages on GitHub

Defined in HTML::Selector

Type at least 2 characters to search.

↑↓ navigate · open · esc close