instance method
attribute_match
Ruby on Rails 4.0.13
Since v2.2.3 Last seen in v4.1.16Signature
attribute_match(equality, value)
Create a regular expression to match an attribute value based on the equality operator (=, ^=, |=, etc).
Parameters
-
equalityreq -
valuereq
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