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.evaluate("")            #=> nil
BlankFilter.evaluate("     ")       #=> nil
BlankFilter.evaluate("  \n ")       #=> nil
BlankFilter.evaluate("1")           #=> "1"
BlankFilter.evaluate("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

.evaluate(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.evaluate(input)
  input.kind_of?(String) && input.blank? ? nil : input
end