Module: DataMapper::Ext::String

Defined in:
lib/dm-core/support/ext/string.rb

Class Method Summary collapse

Class Method Details

.compress_lines(string, spaced = true) ⇒ String

Replace sequences of whitespace (including newlines) with either a single space or remove them entirely (according to param spaced).

compress_lines(<<QUERY)
  SELECT name
  FROM users
QUERY => "SELECT name FROM users"

Parameters:

  • string (String)

    The input string.

  • spaced (TrueClass, FalseClass) (defaults to: true)

    (default=true) Determines whether returned string has whitespace collapsed or removed.

Returns:

  • (String)

    The input string with whitespace (including newlines) replaced.



20
21
22
# File 'lib/dm-core/support/ext/string.rb', line 20

def self.compress_lines(string, spaced = true)
  string.split($/).map { |line| line.strip }.join(spaced ? ' ' : '')
end