Module: Normatron::Filters::StripFilter

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

Class Method Summary collapse

Methods included from Helpers

acronym_regex, acronyms, evaluate_regexp, evaluate_strip, inflections, mb_send

Class Method Details

.evaluate(input, option = :LR) ⇒ String

Remove traling and/or leading spaces from the string.

Examples:

StripFilter.evaluate("   copy   ")      #=> "copy"
StripFilter.evaluate("   copy   ", :L)  #=> "copy   "
StripFilter.evaluate("   copy   ", :R)  #=> "   copy"
StripFilter.evaluate("   copy   ", :LR) #=> "copy"

Using as ActiveRecord::Base normalizer

normalize :attribute_a, :with => :strip
normalize :attribute_b, :with => { :strip => :L }
normalize :attribute_c, :with => [:custom_filter, :strip]
normalize :attribute_d, :with => [:custom_filter, [:strip, :L]]
normalize :attribute_e, :with => [:custom_filter, {:strip => :R}]

Parameters:

  • input (String)

    A character sequence

  • option (Symbol) (defaults to: :LR)

    :L to strip trailing spaces, :R for leading spaces and :LR for both

Returns:

  • (String)

    The character sequence without trailing and leading spaces or the object itself

See Also:



28
29
30
# File 'lib/normatron/filters/strip_filter.rb', line 28

def self.evaluate(input, option=:LR)
  input.kind_of?(String) ? evaluate_strip(input, option) : input
end