W3cubDocs

/Nokogiri

class Nokogiri::CSS::Node

Parent:
Object

Constants

ALLOW_COMBINATOR_ON_SELF

Attributes

type[RW]

Get the type of this node

value[RW]

Get the value of this node

Public Class Methods

new(type, value) Show source
# File lib/nokogiri/css/node.rb, line 12
def initialize type, value
  @type = type
  @value = value
end

Create a new Node with type and value

Public Instance Methods

accept(visitor) Show source
# File lib/nokogiri/css/node.rb, line 18
def accept visitor
  visitor.send(:"visit_#{type.to_s.downcase}", self)
end

Accept visitor

find_by_type(types) Show source
# File lib/nokogiri/css/node.rb, line 30
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

Find a node by type using types

to_a() Show source
# File lib/nokogiri/css/node.rb, line 47
def to_a
  [@type] + @value.map { |n| n.respond_to?(:to_a) ? n.to_a : [n] }
end

Convert to array

to_type() Show source
# File lib/nokogiri/css/node.rb, line 40
def to_type
  [@type] + @value.map { |n|
    n.to_type if n.respond_to?(:to_type)
  }.compact
end

Convert #to_type

to_xpath(prefix = '//', visitor = XPathVisitor.new) Show source
# File lib/nokogiri/css/node.rb, line 24
def to_xpath prefix = '//', visitor = XPathVisitor.new
  prefix = '.' if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil?
  prefix + visitor.accept(self)
end

Convert this CSS node to xpath with prefix using visitor

© 2008–2018 Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo,
Patrick Mahoney, Yoko Harada, Akinori Musha, John Shahid, Lars Kanis
Licensed under the MIT License.