Module: Normatron::Filters::SquishFilter

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

Overview

Strip input, remove line-breaks and multiple spaces.

Examples:

Out of box

SquishFilter.call("   the simpsons   ") #=> "the simpsons"
SquishFilter.call("family      guy")    #=> "family guy"
SquishFilter.call("the \n simpsons")    #=> "the simpsons"
SquishFilter.call("the\nsimpsons")      #=> "the simpsons"

Using as ActiveRecord::Base normalizer

normalize :attribute, :with => [:custom_filter, :squish]

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 squished String


30
31
32
# File 'lib/normatron/filters/squish_filter.rb', line 30

def self.call(input)
  input.kind_of?(String) ? input.squish : input
end