instance method only_child

Ruby on Rails 4.1.16

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

only_child(of_type)

Creates a only child lambda. Pass of-type to only look at elements of its type.

Parameters

of_type req
Source
# File actionview/lib/action_view/vendor/html-scanner/html/selector.rb, line 774
    def only_child(of_type)
      lambda do |element|
        # Element must be inside parent element.
        return false unless element.parent && element.parent.tag?
        name = of_type ? element.name : nil
        other = false
        for child in element.parent.children
          # Skip text nodes/comments.
          if child.tag? && (name == nil || child.name == name)
            unless child.equal?(element)
              other = true
              break
            end
          end
        end
        !other
      end
    end

Defined in actionview/lib/action_view/vendor/html-scanner/html/selector.rb line 774 · 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