Sha256: 6d1d1c3e799e2fe7826e8083e603b76942cb08cfdf28d5a589fe63916a5bd334

Contents?: true

Size: 768 Bytes

Versions: 40

Compression:

Stored size: 768 Bytes

Contents

module Doing
  module ArrayCleanup
    ##
    ## Like Array#compact -- removes nil items, but also
    ## removes empty strings, zero or negative numbers and FalseClass items
    ##
    ## @return     [Array] Array without "bad" elements
    ##
    def remove_bad
      compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?)
    end

    def remove_bad!
      replace remove_empty
    end

    ##
    ## Like Array#compact -- removes nil items, but also
    ## removes empty elements
    ##
    ## @return     [Array] Array without empty elements
    ##
    def remove_empty
      compact.map { |x| x.is_a?(String) ? x.strip : x }.reject { |x| x.is_a?(String) ? x.empty? : false }
    end

    def remove_empty!
      replace remove_empty
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
doing-2.1.65 lib/doing/array/cleanup.rb
doing-2.1.64 lib/doing/array/cleanup.rb
doing-2.1.63 lib/doing/array/cleanup.rb
doing-2.1.62 lib/doing/array/cleanup.rb
doing-2.1.61 lib/doing/array/cleanup.rb
doing-2.1.60 lib/doing/array/cleanup.rb
doing-2.1.58 lib/doing/array/cleanup.rb
doing-2.1.57 lib/doing/array/cleanup.rb
doing-2.1.56 lib/doing/array/cleanup.rb
doing-2.1.55 lib/doing/array/cleanup.rb
doing-2.1.54 lib/doing/array/cleanup.rb
doing-2.1.52 lib/doing/array/cleanup.rb
doing-2.1.49 lib/doing/array/cleanup.rb
doing-2.1.48 lib/doing/array/cleanup.rb
doing-2.1.47 lib/doing/array/cleanup.rb
doing-2.1.46 lib/doing/array/cleanup.rb
doing-2.1.45 lib/doing/array/cleanup.rb
doing-2.1.44 lib/doing/array/cleanup.rb
doing-2.1.43 lib/doing/array/cleanup.rb
doing-2.1.42 lib/doing/array/cleanup.rb