Module: Normalizy::Filters::Strip

Defined in:
lib/normalizy/filters/strip.rb

Class Method Summary collapse

Class Method Details

.call(input, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/normalizy/filters/strip.rb', line 6

def self.call(input, options = {})
  return input unless input.is_a?(String)

  regex = {
    both:  '\A\s*|\s*\z',
    left:  '\A\s*',
    right: '\s*\z',
  }[options[:side] || :both]

  input.gsub Regexp.new(/#{regex}/), ''
end