Module: Normatron::Filters::SqueezeFilter

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

Class Method Summary collapse

Class Method Details

.evaluate(input, *targets) ⇒ String

Remove multiple occurences of the same character. If no option are given, all runs of identical characters are replaced by a single character.

Examples:

SqueezeFilter.evaluate("yellow    moon")               #=> "yelow mon"
SqueezeFilter.evaluate("  now   is  the", " ")         #=> " now is the"
SqueezeFilter.evaluate("putters shoot balls", "m-z")   #=> "puters shot balls"

Using as ActiveRecord::Base normalizer

normalize :attribute_a, :with => [:custom_filter, :squeeze]
normalize :attribute_b, :with => [:custom_filter, [:squeeze, "a-f"]]
normalize :attribute_c, :with => [:custom_filter, {:squeeze => ["a-f"]}]

Parameters:

  • input (String)

    A character sequence

  • targets ([String]*)

    Characters to be affected

Returns:

  • (String)

    The clean character sequence or the object itself

See Also:



24
25
26
27
# File 'lib/normatron/filters/squeeze_filter.rb', line 24

def self.evaluate(input, *targets)
  return input unless input.kind_of?(String)
  targets.any? ? input.squeeze(targets.last) : input.squeeze
end