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) ⇒ 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) ⇒ HashSnakeCaser
Recursively converts CamelCase and camelBack JSON-style hash keys to Rubyish snake_case, suitable for use during instantiation of Ruby model attributes.
9 10 11 |
# File 'lib/chartmogul/utils/hash_snake_caser.rb', line 9 def initialize(hash) @hash = hash end |
Instance Method Details
#to_snake_keys(value = @hash) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/chartmogul/utils/hash_snake_caser.rb', line 13 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 |