Module: Awsmeta::Helpers::Hash
- Defined in:
- lib/awsmeta/helpers/hash/hash.rb
Overview
a set of hash processors
Class Method Summary collapse
Class Method Details
.symbolize_and_underscore_keys(obj) ⇒ Object
20 21 22 23 24 |
# File 'lib/awsmeta/helpers/hash/hash.rb', line 20 def symbolize_and_underscore_keys(obj) obj.each_with_object({}) do |(k, v), h| h[k.nil? ? k : underscore(k).to_sym] = v end end |
.underscore(camel_cased_word) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/awsmeta/helpers/hash/hash.rb', line 10 def underscore(camel_cased_word) return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word) word = camel_cased_word.to_s.gsub('::', '/') word.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |