Class: DeepHashTransformer
- Inherits:
-
Object
- Object
- DeepHashTransformer
- Defined in:
- lib/deep_hash_transformer.rb,
lib/deep_hash_transformer/blank.rb,
lib/deep_hash_transformer/version.rb,
lib/deep_hash_transformer/element_operation.rb,
lib/deep_hash_transformer/collection_operation.rb
Defined Under Namespace
Modules: CollectionOperation, ElementOperation Classes: Blank
Constant Summary collapse
- ELEMENT_OPS =
%i[ camel_case dasherize identity pascal_case snake_case stringify symbolize underscore ].freeze
- COLLECTION_OPS =
%i[ compact compact_blank ].freeze
- OPS =
ELEMENT_OPS + COLLECTION_OPS
- VERSION =
"2.2.1"
Instance Method Summary collapse
-
#initialize(hash) ⇒ DeepHashTransformer
constructor
A new instance of DeepHashTransformer.
- #tr(*ops) ⇒ Object
Constructor Details
#initialize(hash) ⇒ DeepHashTransformer
Returns a new instance of DeepHashTransformer.
26 27 28 |
# File 'lib/deep_hash_transformer.rb', line 26 def initialize(hash) @hash = hash end |
Instance Method Details
#tr(*ops) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/deep_hash_transformer.rb', line 30 def tr(*ops) unknown_transformations = ops.map(&:to_s) - OPS.map(&:to_s) if unknown_transformations.any? raise( ArgumentError, "unknown transformation(s): #{unknown_transformations.join(",")}" ) end transform_value(hash, ops) end |