Class: SiteDiff::Sanitizer::Regexp::WithSelector

Inherits:
SiteDiff::Sanitizer::Regexp show all
Defined in:
lib/sitediff/sanitize/regexp.rb

Overview

A RegExp with selector.

Instance Method Summary collapse

Methods inherited from SiteDiff::Sanitizer::Regexp

create, #initialize

Constructor Details

This class inherits a constructor from SiteDiff::Sanitizer::Regexp

Instance Method Details

#applies?(_html, node) ⇒ Boolean

Whether the RegExp applies to the given markup.

Returns:

  • (Boolean)


55
56
57
# File 'lib/sitediff/sanitize/regexp.rb', line 55

def applies?(_html, node)
  enum_for(:contexts, node).any? { |e| applies_to_string?(e.to_html) }
end

#apply(node) ⇒ Object

Applies the RegExp to the markup.



61
62
63
# File 'lib/sitediff/sanitize/regexp.rb', line 61

def apply(node)
  contexts(node) { |e| e.replace(gsub!(e.to_html)) }
end

#contexts(node, &block) ⇒ Object

TODO: Document what this method does.



48
49
50
51
# File 'lib/sitediff/sanitize/regexp.rb', line 48

def contexts(node, &block)
  selectors = @rule['selector']
  node.css(selectors).each(&block)
end

#selector?Boolean

Whether the RegExp has a selector.

Returns:

  • (Boolean)


42
43
44
# File 'lib/sitediff/sanitize/regexp.rb', line 42

def selector?
  true
end