Class: Sparrow::Strategies::TransformParams
- Inherits:
-
Object
- Object
- Sparrow::Strategies::TransformParams
- Defined in:
- lib/sparrow/strategies/transform_params.rb
Overview
Core class to trigger the conversion
Instance Attribute Summary collapse
-
#key_transformation_strategy ⇒ KeyTransformation
the strategy stating how to convert the JSON.
-
#options ⇒ Object
Key Transformation Strategy options.
Instance Method Summary collapse
-
#initialize(key_transformation_strategy_buzzword, options = {}) ⇒ TransformParams
constructor
Create a new TransformParams instance.
-
#transform(collection_or_hash) ⇒ Array|Hash
Do the transformation.
Constructor Details
#initialize(key_transformation_strategy_buzzword, options = {}) ⇒ TransformParams
Create a new TransformParams instance
30 31 32 33 34 35 |
# File 'lib/sparrow/strategies/transform_params.rb', line 30 def initialize(key_transformation_strategy_buzzword, = {}) self. = key_transformation_strategy = create_key_transformation_strategy( key_transformation_strategy_buzzword) self.key_transformation_strategy = key_transformation_strategy end |
Instance Attribute Details
#key_transformation_strategy ⇒ KeyTransformation
the strategy stating how to convert the JSON
14 15 16 |
# File 'lib/sparrow/strategies/transform_params.rb', line 14 def key_transformation_strategy @key_transformation_strategy end |
#options ⇒ Object
Key Transformation Strategy options. Possible values differ by the specific strategy. E.g. for CamelizeKey options may be the strategy and camlize_uppercase_params
22 23 24 |
# File 'lib/sparrow/strategies/transform_params.rb', line 22 def @options end |
Instance Method Details
#transform(collection_or_hash) ⇒ Array|Hash
Do the transformation
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sparrow/strategies/transform_params.rb', line 44 def transform(collection_or_hash) case collection_or_hash when Array collection_or_hash.map { |element| transform(element) } when Hash collection_or_hash.deep_transform_keys do |key| key_transformation_strategy.transform_key(key) end end end |