Sha256: a4dc266fc6d44d24ea64cc783f4348ec753831a02a0cb45cb532488923312feb

Contents?: true

Size: 967 Bytes

Versions: 2

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

# Copy from https://github.com/rails/rails/blob/45b609c9964242f5c169d913c612eedce2a47397/activesupport/lib/active_support/core_ext/string/filters.rb#L11

class String
  # Returns the string, first removing all whitespace on both ends of
  # the string, and then changing remaining consecutive whitespace
  # groups into one space each.
  #
  # Note that it handles both ASCII and Unicode whitespace.
  #
  #   %{ Multi-line
  #      string }.squish                   # => "Multi-line string"
  #   " foo   bar    \n   \t   boo".squish # => "foo bar boo"
  def squish
    dup.squish!
  end

  # Performs a destructive squish. See String#squish.
  #   str = " foo   bar    \n   \t   boo"
  #   str.squish!                         # => "foo bar boo"
  #   str                                 # => "foo bar boo"
  def squish!
    gsub!(/\A[[:space:]]+/, '')
    gsub!(/[[:space:]]+\z/, '')
    gsub!(/[[:space:]]+/, ' ')
    self
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
r2-oas-0.5.0 lib/r2-oas/lib/core_ext/string/filters.rb
r2-oas-0.4.1 lib/r2-oas/lib/core_ext/string/filters.rb