class DeepHashTransformer
Constants
- OPS
- VERSION
Attributes
hash[R]
Public Class Methods
new(hash)
click to toggle source
# File lib/deep_hash_transformer.rb, line 14 def initialize(hash) @hash = hash end
Public Instance Methods
tr(*ops)
click to toggle source
# File lib/deep_hash_transformer.rb, line 18 def tr(*ops) transform_value(hash, ops) end
Private Instance Methods
transform_key(key, ops)
click to toggle source
# File lib/deep_hash_transformer.rb, line 41 def transform_key(key, ops) return key unless [String, Symbol].include?(key.class) ops.inject(key) { |k, op| OPS.fetch(op).call(k) } end
transform_value(value, ops)
click to toggle source
# File lib/deep_hash_transformer.rb, line 30 def transform_value(value, ops) case value when Array value.map { |e| transform_value(e, ops) } when Hash value.map { |k, v| [transform_key(k, ops), transform_value(v, ops)] }.to_h else value end end