Module: Normatron::Filters::AsciiFilter

Defined in:
lib/normatron/filters/ascii_filter.rb

Overview

Converts Unicode(and accented ASCII) characters to their plain-text ASCII equivalents.

Examples:

Out of box

AsciiFilter.call("EVOLUÇÃO")  #=> "EVOLUCAO"
AsciiFilter.call("⠋⠗⠁⠝⠉⠑")  #=> "france"

Using as model normalizer

normalize :attribute_a, :with => :ascii
normalize :attribute_b, :with => [:custom_filter, :ascii]

See Also:

Class Method Summary collapse

Class Method Details

.call(input) ⇒ 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

Returns:

  • (String)

    A new transliterated String


27
28
29
# File 'lib/normatron/filters/ascii_filter.rb', line 27

def self.call(input)
  input.kind_of?(String) ? Stringex::Unidecoder.decode(input) : input
end