123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::CSS::Node

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/nokogiri/css/node.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

  • #type rw

    Get the type of this node.

  • #value rw

    Get the value of this node.

Instance Method Summary

Constructor Details

.new(type, value) ⇒ Node

Create a new Node with #type and #value

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 14

def initialize(type, value)
  @type = type
  @value = value
end

Instance Attribute Details

#type (rw)

Get the type of this node

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 9

attr_accessor :type

#value (rw)

Get the value of this node

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 11

attr_accessor :value

Instance Method Details

#accept(visitor)

Accept visitor

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 20

def accept(visitor)
  visitor.send(:"visit_#{type.to_s.downcase}", self)
end

#find_by_type(types)

Find a node by type using types

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 36

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

#to_a

Convert to array

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 53

def to_a
  [@type] + @value.map { |n| n.respond_to?(:to_a) ? n.to_a : [n] }
end

#to_type

Convert to_type

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 46

def to_type
  [@type] + @value.filter_map do |n|
    n.to_type if n.respond_to?(:to_type)
  end
end

#to_xpath(visitor)

Convert this ::Nokogiri::CSS node to xpath with prefix using visitor

[ GitHub ]

  
# File 'lib/nokogiri/css/node.rb', line 26

def to_xpath(visitor)
  prefix = if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil?
    "."
  else
    visitor.prefix
  end
  prefix + visitor.accept(self)
end