Module: ApexCharts::Utils::Hash

Included in:
Annotations, BaseChart, CartesianChart, MixedCharts, OptionsBuilder
Defined in:
lib/apexcharts/utils/hash.rb

Class Method Summary collapse

Class Method Details

.camelize(key) ⇒ Object



16
17
18
# File 'lib/apexcharts/utils/hash.rb', line 16

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

.camelize_keys(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/apexcharts/utils/hash.rb', line 20

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



6
7
8
9
10
11
12
13
14
# File 'lib/apexcharts/utils/hash.rb', line 6

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