Module: AbstractMapper::Functions Private
- Extended by:
- Transproc::Registry
- Defined in:
- lib/abstract_mapper/functions.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.
The collection of gem-specific pure functions (transproc)
Class Method Summary collapse
-
.compact(array, fn) ⇒ Array
private
Applies the function to every consecutive pair of array elements, and removes empty values.
-
.filter(array, fn) ⇒ Array
private
Applies the function to every element of array and removes empty values.
-
.identity(value) ⇒ Object
private
Returns the unchanged value whatever parameters are given.
-
.restrict(hash, default_hash) ⇒ Hash
private
Restricts the hash by keys and values of the default one.
-
.subclass?(subling, ancestor) ⇒ Boolean
private
Checks whether the class or module has given ancestor.
Class Method Details
.compact(array, fn) ⇒ 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.
Applies the function to every consecutive pair of array elements, and removes empty values
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/abstract_mapper/functions.rb', line 61 def self.compact(array, fn) array.each_with_object([]) do |i, a| if a.empty? a << i else a[-1] = fn.call(a.last, i) a.flatten! end end end |
.filter(array, fn) ⇒ 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.
Applies the function to every element of array and removes empty values
41 42 43 |
# File 'lib/abstract_mapper/functions.rb', line 41 def self.filter(array, fn) t(:map_array, fn)[array].compact.flatten end |
.identity(value) ⇒ Object
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.
Returns the unchanged value whatever parameters are given
25 26 27 |
# File 'lib/abstract_mapper/functions.rb', line 25 def self.identity(value, *) value end |
.restrict(hash, default_hash) ⇒ Hash
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.
Restricts the hash by keys and values of the default one
95 96 97 98 99 |
# File 'lib/abstract_mapper/functions.rb', line 95 def self.restrict(hash, default_hash) keys = default_hash.keys values = default_hash.merge(hash).values Hash[keys.zip(values)] end |
.subclass?(subling, ancestor) ⇒ Boolean
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.
Checks whether the class or module has given ancestor
84 85 86 |
# File 'lib/abstract_mapper/functions.rb', line 84 def self.subclass?(subling, ancestor) subling.ancestors.include?(ancestor) end |