Module: Normatron::Filters::DumpFilter

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

Overview

Creates a literal string representation with all nonprinting characters replaced by \\n notation and all special characters escaped.

Examples:

Out of box

DumpFilter.call("I'm not\na \"clubber\"...") #=> "\"I'm not\\na \\\"clubber\\\"...\""
DumpFilter.call("I'm not\na \"clubber\"...") #== '"I\'m not\na \"clubber\"..."'
DumpFilter.call('I\'m not\na "clubber"...')  #=> "\"I'm not\\\\na \\\"clubber\\\"...\""
DumpFilter.call('I\'m not\na "clubber"...')  #== '"I\'m not\\\na \"clubber\"..."'

Using as ActiveRecord::Base normalizer

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

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



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

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