Module: WebFunction::Utils Private

Defined in:
lib/web_function/utils.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal utility methods.

Class Method Summary collapse

Class Method Details

.normalize_array(collection) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalizes a collection. Yields each item to the block if a block is given, otherwise returns the item. Any ‘nil` items are removed.

Parameters:

  • collection (Array)

    The collection to normalize

Returns:

  • (Array)

    The normalized array



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/web_function/utils.rb', line 18

def normalize_array(collection)
  unless collection.is_a?(Array)
    return []
  end

  items = collection.map do |item|
    if block_given?
      yield item
    else
      item
    end
  end

  items.compact
end

.normalize_array_of_strings(collection) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalizes an array of strings. Uses #normalize_array under the hood.

Parameters:

  • collection (Array)

    The collection to normalize

Returns:

  • (Array)

    The normalized array



40
41
42
# File 'lib/web_function/utils.rb', line 40

def normalize_array_of_strings(collection)
  normalize_array(collection) { |item| item.to_s }
end