Class: SiteDiff::Sanitizer::Regexp

Inherits:
Object
  • Object
show all
Defined in:
lib/sitediff/sanitize/regexp.rb

Overview

Regular Expression Object.

Direct Known Subclasses

WithSelector

Defined Under Namespace

Classes: WithSelector

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule) ⇒ Regexp

Creates a RegExp object.



9
10
11
# File 'lib/sitediff/sanitize/regexp.rb', line 9

def initialize(rule)
  @rule = rule
end

Class Method Details

.create(rule) ⇒ Object

Creates a RegExp object as per rule.



33
34
35
# File 'lib/sitediff/sanitize/regexp.rb', line 33

def self.create(rule)
  rule['selector'] ? WithSelector.new(rule) : new(rule)
end

Instance Method Details

#applies?(html, _node) ⇒ Boolean

Whether the RegExp applies to the given markup.

Returns:

  • (Boolean)


21
22
23
# File 'lib/sitediff/sanitize/regexp.rb', line 21

def applies?(html, _node)
  applies_to_string?(html)
end

#apply(html) ⇒ Object

Applies the RegExp to the markup.



27
28
29
# File 'lib/sitediff/sanitize/regexp.rb', line 27

def apply(html)
  gsub!(html)
end

#selector?Boolean

Whether the RegExp has a selector.

Returns:

  • (Boolean)


15
16
17
# File 'lib/sitediff/sanitize/regexp.rb', line 15

def selector?
  false
end