Module: Doing::ArrayCleanup

Defined in:
lib/doing/array/cleanup.rb

Instance Method Summary collapse

Instance Method Details

#remove_badArray

Like Array#compact -- removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items

Returns:

  • (Array)

    Array without "bad" elements



11
12
13
# File 'lib/doing/array/cleanup.rb', line 11

def remove_bad
  compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?)
end

#remove_bad!Object



15
16
17
# File 'lib/doing/array/cleanup.rb', line 15

def remove_bad!
  replace remove_empty
end

#remove_emptyArray

Like Array#compact -- removes nil items, but also removes empty elements

Returns:

  • (Array)

    Array without empty elements



25
26
27
# File 'lib/doing/array/cleanup.rb', line 25

def remove_empty
  compact.map { |x| x.is_a?(String) ? x.strip : x }.reject { |x| x.is_a?(String) ? x.empty? : false }
end

#remove_empty!Object



29
30
31
# File 'lib/doing/array/cleanup.rb', line 29

def remove_empty!
  replace remove_empty
end