Sha256: cda32679530ea18b68ac53a7deb6d683172516dabd72efd1f5068f209e2f4493
Contents?: true
Size: 683 Bytes
Versions: 2
Compression:
Stored size: 683 Bytes
Contents
# frozen_string_literal: true module Strings module Fold LINE_BREAK = "(\r\n+|\r+|\n+|\t+)".freeze # Fold a multiline text into a single line string # # @example # fold("\tfoo \r\n\n bar") # => " foo bar" # # @param [String] text # # @param [String] separator # the separators to be removed from the text, default: (\r\n+|\r+|\n+|\t+) # # @return [String] # # @api public def fold(text, separator = LINE_BREAK) text.gsub(/([ ]+)#{separator}/, "\\1") .gsub(/#{separator}(?<space>[ ]+)/, "\\k<space>") .gsub(/#{separator}/, " ") end module_function :fold end # Fold end # Strings
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
strings-0.2.1 | lib/strings/fold.rb |
strings-0.2.0 | lib/strings/fold.rb |