Class: MapWithIndifferentAccess::Normalization::DeepNormalizer
- Inherits:
-
Object
- Object
- MapWithIndifferentAccess::Normalization::DeepNormalizer
- Defined in:
- lib/map_with_indifferent_access/normalization/deep_normalizer.rb
Instance Attribute Summary collapse
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#call(obj) ⇒ Object
Given an
Array-like orHash-like object, returns a similar object with keys coerced according to the target DeepNormalizer's strategy. -
#initialize(strategy) ⇒ DeepNormalizer
constructor
Initializes a new DeepNormalizer with a given object that extends KeyStrategy.
Constructor Details
#initialize(strategy) ⇒ DeepNormalizer
Initializes a new DeepNormalizer with a given object that extends KeyStrategy.
9 10 11 |
# File 'lib/map_with_indifferent_access/normalization/deep_normalizer.rb', line 9 def initialize(strategy) @strategy = strategy end |
Instance Attribute Details
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
5 6 7 |
# File 'lib/map_with_indifferent_access/normalization/deep_normalizer.rb', line 5 def strategy @strategy end |
Instance Method Details
#call(obj) ⇒ Object
Given an Array-like or Hash-like object, returns a
similar object with keys coerced according to the
target MapWithIndifferentAccess::Normalization::DeepNormalizer's strategy.
Given an object that is not Array-like or Hash-like,
then the given object is returned.
During this process, any hash entry values or array
items that are instances of
Map or List are replaced with Hash or Array
deconstructions respectively. If a Map or List is
given, then the same type of object is returned.
If a Hash or an object that resonds to #to_hash and
#each_pair is given, then a Hash is returned. The
same applies to each Hash/Map entry value or
Array/List item that is traversed.
If an Array or an object that resonds to #to_ary is
given, then an Array is returned. The same applies to
each Hash/Map entry value or Array/List item that
is traversed.
If any keys, Hash entry values, or Array items are
replaced, then a new object is returned that includes
those replacements. Otherwise, the given object is
returned. In either case, the contents of obj are not
modified.
40 41 42 43 44 45 46 47 |
# File 'lib/map_with_indifferent_access/normalization/deep_normalizer.rb', line 40 def call(obj) if WrapsCollection === obj coerced_inner_col = recursively_coerce( obj ) Values.externalize( coerced_inner_col ) else recursively_coerce( obj ) end end |