Class: SecEdgarRuby::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/sec_edgar_ruby/util.rb

Class Method Summary collapse

Class Method Details

.deep_snake_case_keys(hash, except_mapping = {}) ⇒ Object

except_mapping just use for level 1 keys except_mapping = { ‘old_key’: ‘new_key’ }



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sec_edgar_ruby/util.rb', line 5

def self.deep_snake_case_keys(hash, except_mapping = {})
  return hash unless hash.is_a?(Hash)
  return hash if hash.blank?

  result = hash.deep_transform_keys { |key| key.to_s.underscore.to_sym }

  except_mapping.each do |key, value|
    result[:"#{value}"] = result.delete :"#{key}" if result.keys.include? key
  end

  result
end