Class: ChartMogul::Utils::HashSnakeCaser
- Inherits:
-
Object
- Object
- ChartMogul::Utils::HashSnakeCaser
- Defined in:
- lib/chartmogul/utils/hash_snake_caser.rb
Instance Method Summary collapse
-
#initialize(hash, immutable_keys: []) ⇒ HashSnakeCaser
constructor
Recursively converts CamelCase and camelBack JSON-style hash keys to Rubyish snake_case, suitable for use during instantiation of Ruby model attributes.
- #to_snake_keys(value = @hash) ⇒ Object
Constructor Details
#initialize(hash, immutable_keys: []) ⇒ HashSnakeCaser
Recursively converts CamelCase and camelBack JSON-style hash keys to Rubyish snake_case, suitable for use during instantiation of Ruby model attributes.
11 12 13 14 |
# File 'lib/chartmogul/utils/hash_snake_caser.rb', line 11 def initialize(hash, immutable_keys: []) @hash = hash @immutable_keys = immutable_keys end |
Instance Method Details
#to_snake_keys(value = @hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/chartmogul/utils/hash_snake_caser.rb', line 16 def to_snake_keys(value = @hash) case value when Array value.map { |v| to_snake_keys(v) } when Hash snake_hash(value) else value end end |