Class: Nokogiri::XML::Node

Inherits:
Object show all
Defined in:
lib/kitchen/patches/nokogiri.rb

Overview

Monkey patches for Nokogiri::XML::Node

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.selector_to_css_nodes(selector) ⇒ Object



78
79
80
81
82
# File 'lib/kitchen/patches/nokogiri.rb', line 78

def self.selector_to_css_nodes(selector)
  # No need to parse the same selector more than once.
  @parsed_selectors ||= {}
  @parsed_selectors[selector] ||= Nokogiri::CSS::Parser.new.parse(selector)
end

Instance Method Details

#classesObject



66
67
68
# File 'lib/kitchen/patches/nokogiri.rb', line 66

def classes
  self[:class]&.split || []
end

#inspectString

Calls to_s on the node

Returns:



58
59
60
# File 'lib/kitchen/patches/nokogiri.rb', line 58

def inspect
  to_s
end

#preceded_by_text?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'lib/kitchen/patches/nokogiri.rb', line 70

def preceded_by_text?
  prev = previous_sibling
  while !prev.nil? && prev.blank? do prev = prev.previous_sibling end
  return false if prev.nil?

  prev.text?
end

#quick_matches?(selector) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/kitchen/patches/nokogiri.rb', line 62

def quick_matches?(selector)
  self.class.selector_to_css_nodes(selector).any? { |css_node| matches_css_node?(css_node) }
end