Class: Detergent::Matchers::ObviousJunkMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/detergent/matchers/obvious_junk_matcher.rb

Instance Method Summary collapse

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/detergent/matchers/obvious_junk_matcher.rb', line 4

def match?(node)
  tag = node.name.downcase

  # Always remove these tags
  return true if %w(script style link iframe noscript).include?(tag)

  # Remove hidden elements
  return true if node['aria-hidden'] == 'true'

  # Remove display:none elements
  style = node['style'].to_s.downcase
  return true if style.include?('display:none') || style.include?('display: none')

  # Remove structural navigation
  return true if %w(nav header footer).include?(tag)
  return true if node['role'].to_s.downcase == 'navigation'

  false
end