Class: Nokogiri::XML::Node
Overview
Monkey patches for Nokogiri::XML::Node
Class Method Summary collapse
Instance Method Summary collapse
- #classes ⇒ Object
-
#inspect ⇒ String
Calls to_s on the node.
- #preceded_by_text? ⇒ Boolean
- #quick_matches?(selector) ⇒ Boolean
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
#classes ⇒ Object
66 67 68 |
# File 'lib/kitchen/patches/nokogiri.rb', line 66 def classes self[:class]&.split || [] end |
#inspect ⇒ String
Calls to_s on the node
58 59 60 |
# File 'lib/kitchen/patches/nokogiri.rb', line 58 def inspect to_s end |
#preceded_by_text? ⇒ 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
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 |