Class: SiteDiff::Sanitizer::Regexp::WithSelector
- Inherits:
-
SiteDiff::Sanitizer::Regexp
- Object
- SiteDiff::Sanitizer::Regexp
- SiteDiff::Sanitizer::Regexp::WithSelector
- Defined in:
- lib/sitediff/sanitize/regexp.rb
Overview
A RegExp with selector.
Instance Method Summary collapse
-
#applies?(_html, node) ⇒ Boolean
Whether the RegExp applies to the given markup.
-
#apply(node) ⇒ Object
Applies the RegExp to the markup.
-
#contexts(node, &block) ⇒ Object
TODO: Document what this method does.
-
#selector? ⇒ Boolean
Whether the RegExp has a selector.
Methods inherited from SiteDiff::Sanitizer::Regexp
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.
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.
42 43 44 |
# File 'lib/sitediff/sanitize/regexp.rb', line 42 def selector? true end |