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 32

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 49

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 42

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

#to_xpath(prefix, visitor)

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

[ GitHub ]

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

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