Method: XRay::HTML::Element#match?
- Defined in:
- lib/html/query.rb
#match?(str) ⇒ Boolean Also known as: ===
This method implemented CSS selector for HTML (like Sizzle) very simply. It is not fully supported CSS selector.
TODO: support full CSS3 selector
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/html/query.rb', line 21 def match?(str) return false if is_a?(TextElement) obj = query_obj(str) tag = obj[:tag] cls = obj[:classes] props = obj[:properties] unless tag.nil? or tag_name_equal? tag return false end classes = prop_value(:class) cls.each { |c| return false unless classes.include? c } props.each do |n, v| if v.nil? return false unless has_prop? n else return false unless prop_value(n) == v end end true end |