Sha256: c92c780da64fbc0ef5c1d31c46520e96637737c9df6f5e910f47af2b843a4c5d

Contents?: true

Size: 784 Bytes

Versions: 15

Compression:

Stored size: 784 Bytes

Contents

module Ardm; module Ext
  module 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"
    #
    # @param [String] string
    #   The input string.
    #
    # @param [TrueClass, FalseClass] spaced (default=true)
    #   Determines whether returned string has whitespace collapsed or removed.
    #
    # @return [String] The input string with whitespace (including newlines) replaced.
    #
    # @api semipublic
    def self.compress_lines(string, spaced = true)
      string.split($/).map { |line| line.strip }.join(spaced ? ' ' : '')
    end
  end
end; end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ardm-0.4.0.ar427 lib/ardm/support/ext/string.rb
ardm-0.4.0 lib/ardm/support/ext/string.rb
ardm-0.3.2 lib/ardm/support/ext/string.rb
ardm-0.3.1 lib/ardm/support/ext/string.rb
ardm-0.3.0 lib/ardm/support/ext/string.rb
ardm-0.2.7 lib/ardm/support/ext/string.rb
ardm-0.2.6 lib/ardm/support/ext/string.rb
ardm-0.2.5 lib/ardm/support/ext/string.rb
ardm-0.2.4 lib/ardm/support/ext/string.rb
ardm-0.2.3 lib/ardm/support/ext/string.rb
ardm-0.2.2 lib/ardm/support/ext/string.rb
ardm-0.2.1 lib/ardm/support/ext/string.rb
ardm-0.2.0 lib/ardm/support/ext/string.rb
ardm-0.1.0 lib/ardm/support/ext/string.rb
ardm-0.0.1 lib/ardm/support/ext/string.rb