Module: Normatron::Filters::BlankFilter

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

Overview

Returns nil for a blank string or the string itself otherwise.

Examples:

Out of box

BlankFilter.call("")            #=> nil
BlankFilter.call("     ")       #=> nil
BlankFilter.call("  \n ")       #=> nil
BlankFilter.call("1")           #=> "1"
BlankFilter.call("It's blank?") #=> "It's blank?"

Using as model normalizer

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

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, nil)

    The object itself or nil



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

def self.call(input)
  input.kind_of?(String) && input.blank? ? nil : input
end