Module: Normatron::Filters::RemoveFilter

Extended by:
Helpers
Defined in:
lib/normatron/filters/remove_filter.rb

Class Method Summary collapse

Methods included from Helpers

acronym_regex, acronyms, evaluate_regexp, inflections, mb_send

Class Method Details

.evaluate(input, *properties) ⇒ String

TODO:

Raise exception for empty properties

Remove the characters that match the given properties.

For additional informations see Normatron::Filter::ClassMethods#keep documentation.

Examples:

RemoveFilter.evaluate("Quake 3", :L)      #=> " 3"        remove only letters
RemoveFilter.evaluate("Quake 3", :N)      #=> "Quake "    remove only numbers
RemoveFilter.evaluate("Quake 3", :L, :N)  #=> " "         remove only letters or numbers
RemoveFilter.evaluate("Quake 3", :Lu, :N) #=> "uake "     remove only uppercased letters or numbers
RemoveFilter.evaluate("Quake ˩", :Latin)  #=> " ˩"        remove only latin characters

Using as ActiveRecord::Base normalizer

normalize :attribute_a, :with => [[:remove, :Lu]]
normalize :attribute_b, :with => [{:remove =>[:Lu]}]
normalize :attribute_c, :with => [:custom_filter, [:remove, :Ll, :Space]]
normalize :attribute_d, :with => [:custom_filter, {:remove => [:Ll, :Space]}]

Parameters:

  • input (String)

    A character sequence

  • properties ([Symbol]*)

    Array of Symbols equivalent to Regexp property for \p{} construct.

Returns:

  • (String)

    The clean character sequence or the object itself

See Also:



32
33
34
# File 'lib/normatron/filters/remove_filter.rb', line 32

def self.evaluate(input, *properties)
  input.kind_of?(String) ? evaluate_regexp(input, :remove, properties) : input
end