Class: BigqueryMigration::HashUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/bigquery_migration/hash_util.rb

Class Method Summary collapse

Class Method Details

.deep_stringify_keys(hash) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bigquery_migration/hash_util.rb', line 19

def self.deep_stringify_keys(hash)
  if hash.is_a?(Hash)
    hash.map do |key, val|
      new_key = key.to_s
      new_val = deep_stringify_keys(val)
      [new_key, new_val]
    end.to_h
  elsif hash.is_a?(Array)
    hash.map do |val|
      deep_stringify_keys(val)
    end
  else
    hash
  end
end

.deep_symbolize_keys(hash) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bigquery_migration/hash_util.rb', line 3

def self.deep_symbolize_keys(hash)
  if hash.is_a?(Hash)
    hash.map do |key, val|
      new_key = key.to_sym
      new_val = deep_symbolize_keys(val)
      [new_key, new_val]
    end.to_h
  elsif hash.is_a?(Array)
    hash.map do |val|
      deep_symbolize_keys(val)
    end
  else
    hash
  end
end