Sha256: dbbcf02a429c9a090a2823a032fcbcb92b148bf3ae23026afaf81e4199635200
Contents?: true
Size: 1.37 KB
Versions: 163
Compression:
Stored size: 1.37 KB
Contents
# frozen_string_literal: true module Nokogiri module CSS class Node ALLOW_COMBINATOR_ON_SELF = [:DIRECT_ADJACENT_SELECTOR, :FOLLOWING_SELECTOR, :CHILD_SELECTOR] # Get the type of this node attr_accessor :type # Get the value of this node attr_accessor :value # Create a new Node with +type+ and +value+ def initialize type, value @type = type @value = value end # Accept +visitor+ def accept visitor visitor.send(:"visit_#{type.to_s.downcase}", self) end ### # Convert this CSS node to xpath with +prefix+ using +visitor+ def to_xpath prefix = '//', visitor = XPathVisitor.new prefix = '.' if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil? prefix + visitor.accept(self) end # Find a node by type using +types+ def find_by_type types matches = [] matches << self if to_type == types @value.each do |v| matches += v.find_by_type(types) if v.respond_to?(:find_by_type) end matches end # Convert to_type def to_type [@type] + @value.map { |n| n.to_type if n.respond_to?(:to_type) }.compact end # Convert to array def to_a [@type] + @value.map { |n| n.respond_to?(:to_a) ? n.to_a : [n] } end end end end
Version data entries
163 entries across 156 versions & 6 rubygems
Version | Path |
---|---|
nokogiri-1.11.0.rc1-x86-mingw32 | lib/nokogiri/css/node.rb |
nokogiri-1.11.0.rc1-x64-mingw32 | lib/nokogiri/css/node.rb |
nokogiri-1.11.0.rc1-java | lib/nokogiri/css/node.rb |