Module: DevSuite::Utils::Data::Transformations
- Included in:
- DevSuite::Utils::Data
- Defined in:
- lib/dev_suite/utils/data/transformations.rb
Instance Method Summary collapse
-
#deep_stringify_values(data) ⇒ Object
Recursively convert all values to strings without altering the structure.
-
#deep_symbolize_keys(data) ⇒ Object
Recursively symbolize keys in a nested structure.
Instance Method Details
#deep_stringify_values(data) ⇒ Object
Recursively convert all values to strings without altering the structure
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dev_suite/utils/data/transformations.rb', line 8 def deep_stringify_values(data) case data when Hash data.each_with_object({}) do |(key, value), result| result[key] = deep_stringify_values(value) # Recursively process nested values end when Array data.map { |item| deep_stringify_values(item) } else data.to_s # Only convert the value itself to a string end end |
#deep_symbolize_keys(data) ⇒ Object
Recursively symbolize keys in a nested structure
22 23 24 |
# File 'lib/dev_suite/utils/data/transformations.rb', line 22 def deep_symbolize_keys(data) traverse_transform(data) { |key, value| [key.to_sym, value] } end |