Module: Normatron::Filters::RemoveFilter

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

Overview

Remove the characters that match the given properties.

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

Examples:

Out of box

RemoveFilter.call("Quake 3", :L)      #=> " 3"        remove only letters
RemoveFilter.call("Quake 3", :N)      #=> "Quake "    remove only numbers
RemoveFilter.call("Quake 3", :L, :N)  #=> " "         remove only letters or numbers
RemoveFilter.call("Quake 3", :Lu, :N) #=> "uake "     remove only uppercased letters or numbers
RemoveFilter.call("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]}]

See Also:

Class Method Summary collapse

Methods included from Helpers

acronym_regex, acronyms, evaluate_regexp, inflections, mb_send

Class Method Details

.call(input, *properties) ⇒ String

Performs input conversion according to filter requirements.

This method returns the object itself when the first argument is not a String.

Parameters:

  • input (String)

    The String to be filtered

  • properties ([Symbol]*)

    Symbols equivalent to Regexp property for \\p{} construct

Returns:

  • (String)

    A new clean String


37
38
39
# File 'lib/normatron/filters/remove_filter.rb', line 37

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