Module: HtmlSlicer::Utilities::NodeMatchExtension
- Included in:
- Mappers::Resizing, Mappers::Slicing
- Defined in:
- lib/html_slicer/utilities.rb
Instance Method Summary collapse
-
#able_to?(node, options) ⇒ Boolean
Checking if node is included in
:only
parameter and/or excluded of:except
parameeter. -
#general_match(node, hashes = []) ⇒ Object
Checking if node is a member of other node’s tree.
Instance Method Details
#able_to?(node, options) ⇒ Boolean
Checking if node is included in :only
parameter and/or excluded of :except
parameeter.
24 25 26 27 28 29 30 31 32 |
# File 'lib/html_slicer/utilities.rb', line 24 def able_to?(node, ) if .only.present? general_match(node, .only) elsif .except.present? !general_match(node, .except) else true end end |
#general_match(node, hashes = []) ⇒ Object
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.
36 37 38 39 40 41 42 |
# 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 |