module HtmlSlicer::Utilities::NodeMatchExtension
Public Instance Methods
able_to?(node, options)
click to toggle source
Checking if node is included in :only
parameter and/or excluded of :except
parameeter.
# File lib/html_slicer/utilities.rb, line 24 def able_to?(node, options) if options.only.present? general_match(node, options.only) elsif options.except.present? !general_match(node, options.except) else true end end
general_match(node, hashes = [])
click to toggle source
Checking if node is a member of other node's tree. Accepts hashes
as conditions. Returns true
if node or it's parent matches at least one condition, or false
otherwise.
# File lib/html_slicer/utilities.rb, line 36 def general_match(node, hashes = []) conditions = Array.wrap(hashes) while node break true if conditions.each {|condition| break true if node.match(condition)} == true node = node.parent end||false end