Sha256: f3f700fc04abfb942497057afa09816948b9306186d610748c56b6d96ebe1f29

Contents?: true

Size: 761 Bytes

Versions: 26

Compression:

Stored size: 761 Bytes

Contents

unless String.method_defined? :squish
  class String
    # Strips leading and trailing whitespace and squashes internal whitespace.
    #
    # @return [String] a new string with no leading and trailing
    #   whitespace and no consecutive whitespace characters inside it
    #
    # @example
    #   ' Peter   Parker'.squish #=> 'Peter Parker'
    def squish
      dup.squish!
    end

    # Strips leading and trailing whitespace and squashes internal whitespace.
    #
    # @return [String] the string with no leading and trailing whitespace and no
    #   consecutive whitespace characters inside it
    #
    # @example
    #   ' Peter   Parker'.squish #=> 'Peter Parker'
    def squish!
      strip!
      gsub!(/\s+/, ' ')
      self
    end
  end
end

Version data entries

26 entries across 23 versions & 6 rubygems

Version Path
powerpack-0.1.3 lib/powerpack/string/squish.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/string/squish.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/string/squish.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/string/squish.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/string/squish.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/string/squish.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/powerpack-0.1.2/lib/powerpack/string/squish.rb
powerpack-0.1.2 lib/powerpack/string/squish.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/string/squish.rb
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/lib/powerpack/string/squish.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/lib/powerpack/string/squish.rb
powerpack-0.1.1 lib/powerpack/string/squish.rb