Module: BlankEmptyNilFilters::ArrayExtensions

Includes:
FilterMethods
Defined in:
lib/blank_empty_nil_filters.rb

Instance Method Summary collapse

Methods included from FilterMethods

#maybe_apply, #maybe_recurse

Instance Method Details

#is_blank?(start = 0, depth = nil, level = 0) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/blank_empty_nil_filters.rb', line 60

def is_blank?(start = 0, depth = nil, level = 0)
  is_empty? || no_blank_values(start, depth, level).length.zero?
end

#is_empty?(start = 0, depth = nil, level = 0) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/blank_empty_nil_filters.rb', line 56

def is_empty?(start = 0, depth = nil, level = 0)
  length.zero? || no_empty_values(start, depth, level).length.zero?
end

#no_blank_values(start = 0, depth = nil, level = 0) ⇒ Object Also known as: reject_blank_values



31
32
33
# File 'lib/blank_empty_nil_filters.rb', line 31

def no_blank_values(start = 0, depth = nil, level = 0)
  reject_values(:is_blank?, start, depth, level)
end

#no_empty_values(start = 0, depth = nil, level = 0) ⇒ Object Also known as: reject_empty_values



26
27
28
# File 'lib/blank_empty_nil_filters.rb', line 26

def no_empty_values(start = 0, depth = nil, level = 0)
  reject_values(:is_empty?, start, depth, level)
end

#no_nil_values(start = 0, depth = nil, level = 0) ⇒ Object Also known as: reject_nil_values



36
37
38
# File 'lib/blank_empty_nil_filters.rb', line 36

def no_nil_values(start = 0, depth = nil, level = 0)
  reject_values(:nil?, start, depth, level)
end

#only_blank_values(start = 0, depth = nil, level = 0) ⇒ Object Also known as: select_blank_values



46
47
48
# File 'lib/blank_empty_nil_filters.rb', line 46

def only_blank_values(start = 0, depth = nil, level = 0)
  select_values(:is_blank?, start, depth, level)
end

#only_empty_values(start = 0, depth = nil, level = 0) ⇒ Object Also known as: select_empty_values



41
42
43
# File 'lib/blank_empty_nil_filters.rb', line 41

def only_empty_values(start = 0, depth = nil, level = 0)
  select_values(:is_empty?, start, depth, level)
end

#only_nil_values(start = 0, depth = nil, level = 0) ⇒ Object Also known as: select_nil_values



51
52
53
# File 'lib/blank_empty_nil_filters.rb', line 51

def only_nil_values(start = 0, depth = nil, level = 0)
  select_values(:is_nil?, start, depth, level)
end

#reject_values(condition, start = 0, depth = nil, level = 0) ⇒ Array Also known as: no_values

Returns the filtered array after having recursively applied condition to each element and removing those for which the condition is true.

Parameters:

  • condition (Symbol)

    the name of the filter method (eg: :is_empty?)

  • start (Integer) (defaults to: 0)

    the starting level at which filtering occurs; default: 0

  • depth (Integer|nil) (defaults to: nil)

    the maximum level at which filtering occurs; defaults to nil for no limit

  • level (Integer) (defaults to: 0)

    the current level; defaults to 0

Returns:

  • (Array)

    the filtered array after having recursively applied condition to each element and removing those for which the condition is true



70
71
72
# File 'lib/blank_empty_nil_filters.rb', line 70

def reject_values(condition, start = 0, depth = nil, level = 0)
  filter_values(:reject_values, :reject, condition, start, depth, level)
end

#select_values(condition, start = 0, depth = nil, level = 0) ⇒ Array Also known as: only_values

Returns the filtered array after having recursively applied condition to each element element and selecting out those for which the condition is true.

Parameters:

  • condition (Symbol)

    the name of the filter method (eg: :is_empty?)

  • start (Integer) (defaults to: 0)

    the starting level at which filtering occurs; default: 0

  • depth (Integer|nil) (defaults to: nil)

    the maximum level at which filtering occurs; nil = no limit

  • level (Integer) (defaults to: 0)

    the current level; defaults to 0

Returns:

  • (Array)

    the filtered array after having recursively applied condition to each element element and selecting out those for which the condition is true



81
82
83
# File 'lib/blank_empty_nil_filters.rb', line 81

def select_values(condition, start = 0, depth = nil, level = 0)
  filter_values(:select_values, :select, condition, start, depth, level)
end