Class: Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/filters/uri.rb,
lib/filters/email.rb,
lib/filters/filter.rb,
lib/filters/markup.rb,
lib/filters/phrase.rb,
lib/filters/version.rb,
lib/filters/profanity.rb

Direct Known Subclasses

Email, Markup, Phrase, URI

Defined Under Namespace

Classes: Email, Markup, Phrase, Profanity, URI

Constant Summary collapse

VERSION =
'1.1.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, options = {}) ⇒ Filter

Initialize with string and options.



12
13
14
# File 'lib/filters/filter.rb', line 12

def initialize string, options = {}
  @string, @options = string, options
end

Instance Attribute Details

#stringObject (readonly)

Input string.



7
8
9
# File 'lib/filters/filter.rb', line 7

def string
  @string
end

Class Method Details

.inherited(subclass) ⇒ Object

Auto generate Filter::Subclass() methods which act as a shortcut to Filter::Subclass.new(…).filter



27
28
29
30
31
32
33
34
# File 'lib/filters/filter.rb', line 27

def self.inherited subclass
  (class << self; self end).send :define_method, subclass.name.split('::').last do |*args|
    subclass.new(*args).filter
  end
  (class << self; self end).send :define_method, subclass.name.split('::').last + '!' do |*args|
    subclass.new(*args).filter!
  end
end

.Profanity(*args) ⇒ Object



305
306
307
# File 'lib/filters/profanity.rb', line 305

def self.Profanity *args
  Profanity.new(*args).filter
end

.Profanity!(*args) ⇒ Object



301
302
303
# File 'lib/filters/profanity.rb', line 301

def self.Profanity! *args
  Profanity.new(*args).filter!
end

Instance Method Details

#filterObject

Non-mutative filter.



19
20
21
# File 'lib/filters/filter.rb', line 19

def filter
  @string = string.dup and filter!
end