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
-
ALLOW_COMBINATOR_ON_SELF =
# File 'lib/nokogiri/css/node.rb', line 6[:DIRECT_ADJACENT_SELECTOR, :FOLLOWING_SELECTOR, :CHILD_SELECTOR]
Class Method Summary
- .new(type, value) ⇒ Node constructor
Instance Attribute Summary
Instance Method Summary
-
#accept(visitor)
Accept
visitor
-
#find_by_type(types)
Find a node by type using
types
-
#to_a
Convert to array.
-
#to_type
Convert to_type.
-
#to_xpath(visitor)
Convert this
::Nokogiri::CSS
node to xpath withprefix
usingvisitor
Constructor Details
.new(type, value) ⇒ Node
[ GitHub ]
Instance Attribute Details
#type (rw)
Get the type of this node
# File 'lib/nokogiri/css/node.rb', line 9
attr_accessor :type
#value (rw)
Get the value of this node
# File 'lib/nokogiri/css/node.rb', line 11
attr_accessor :value
Instance Method Details
#accept(visitor)
Accept visitor
# 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
# 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
# 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
# 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
# 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