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



9
10
11
# File 'lib/doing/array/cleanup.rb', line 9

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

#remove_bad!Object



13
14
15
# File 'lib/doing/array/cleanup.rb', line 13

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



23
24
25
# File 'lib/doing/array/cleanup.rb', line 23

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



27
28
29
# File 'lib/doing/array/cleanup.rb', line 27

def remove_empty!
  replace remove_empty
end