Module: Normatron::Filters::DumpFilter

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

Class Method Summary collapse

Class Method Details

.evaluate(input) ⇒ String

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

Examples:

DumpFilter.evaluate("I'm not\na \"clubber\"...") #=> "\"I'm not\\na \\\"clubber\\\"...\""
DumpFilter.evaluate("I'm not\na \"clubber\"...") #== '"I\'m not\na \"clubber\"..."'
DumpFilter.evaluate('I\'m not\na "clubber"...')  #=> "\"I'm not\\\\na \\\"clubber\\\"...\""
DumpFilter.evaluate('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]

Parameters:

  • input (String)

    A character sequence

Returns:

  • (String)

    The dumpped character sequence or the object itself

See Also:



22
23
24
# File 'lib/normatron/filters/dump_filter.rb', line 22

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