Module: HtmlSlicer::Utilities::NodeMatchExtension

Included in:
Mappers::Resizing, Mappers::Slicing
Defined in:
lib/html_slicer/utilities.rb

Instance Method Summary collapse

Instance Method Details

#able_to?(node, options) ⇒ Boolean

Checking if node is included in :only parameter and/or excluded of :except parameeter.

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# 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 = []) ⇒ 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