Module: Normatron::Filters::ChompFilter

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

Class Method Summary collapse

Class Method Details

.evaluate(input, separator = $/) ⇒ String

Remove the given record separator from the end of the string (If present). If $/ has not been changed from the default Ruby record separator, then chomp also removes carriage return characters (that is it will remove \n, \r, and \r\n).

Examples:

ChompFilter.evaluate("Bon Scott\n")            #=> "Bon Scott"
ChompFilter.evaluate("Bon Scott\r")            #=> "Bon Scott"
ChompFilter.evaluate("Bon Scott\r\n")          #=> "Bon Scott"
ChompFilter.evaluate("Bon Scott\n\r")          #=> "Bon Scott\n"
ChompFilter.evaluate("Bon Scott", " Scott")    #=> "Bon"

Using as ActiveRecord::Base normalizer

normalize :attribute_a, :with => :chomp
normalize :attribute_b, :with => [:custom_filter, :chomp]
normalize :attribute_c, :with => [[:chomp, "x"]]
normalize :attribute_d, :with => [{:chomp => "y"}]
normalize :attribute_e, :with => [:custom_filter, [:chomp, "z"]]
normalize :attribute_f, :with => [:custom_filter, {:chomp => "\f"}]

Parameters:

  • input (String)

    A character sequence

  • separator (String) (defaults to: $/)

    A character sequence

Returns:

  • (String)

    The chopped character sequence or the object itself

See Also:



29
30
31
# File 'lib/normatron/filters/chomp_filter.rb', line 29

def self.evaluate(input, separator=$/)
  input.kind_of?(String) ? input.chomp(separator) : input
end