Module: ApexCharts::Utils::Hash

Class Method Summary collapse

Class Method Details

.camelize(key) ⇒ Object



18
19
20
# File 'lib/apex_charts/utils/hash.rb', line 18

def camelize(key)
  key.to_s.gsub(/_(.)/) {|m| m[1].upcase }.to_sym
end

.camelize_keys(value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/apex_charts/utils/hash.rb', line 22

def camelize_keys(value)
  case value
  when ::Hash
    ::Hash[value.map {|k, v| [camelize(k), camelize_keys(v)] }]
  when Array
    value.map {|e| camelize_keys(e) }
  else
    value
  end
end

.deep_merge(first_hash, second_hash) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/apex_charts/utils/hash.rb', line 8

def deep_merge(first_hash, second_hash)
  first_hash.merge(second_hash) do |_key, this_val, other_val|
    if this_val.is_a?(::Hash) && other_val.is_a?(::Hash)
      deep_merge(this_val.dup, other_val)
    else
      other_val
    end
  end
end