Sha256: 7b1a940a61e004b73c77e48b50c37f56b239c8cfa893db29857886fa255b4720

Contents?: true

Size: 383 Bytes

Versions: 11

Compression:

Stored size: 383 Bytes

Contents

# frozen_string_literal: true

module Normalizy
  module Filters
    module Strip
      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
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
normalizy-1.6.0 lib/normalizy/filters/strip.rb
normalizy-1.5.0 lib/normalizy/filters/strip.rb
normalizy-1.4.0 lib/normalizy/filters/strip.rb
normalizy-1.3.0 lib/normalizy/filters/strip.rb
normalizy-1.2.0 lib/normalizy/filters/strip.rb
normalizy-1.1.1 lib/normalizy/filters/strip.rb
normalizy-1.1.0 lib/normalizy/filters/strip.rb
normalizy-1.0.1 lib/normalizy/filters/strip.rb
normalizy-1.0.0 lib/normalizy/filters/strip.rb
normalizy-0.2.0 lib/normalizy/filters/strip.rb
normalizy-0.1.0 lib/normalizy/filters/strip.rb