Module: Humidifier::Utils
- Defined in:
- lib/humidifier/utils.rb
Overview
Dumps an object to CFN syntax
Class Method Summary collapse
-
.underscore(name) ⇒ Object
convert from UpperCamelCase to lower_snake_case.
-
.underscored(names) ⇒ Object
a frozen hash of the given names mapped to their underscored version.
Class Method Details
.underscore(name) ⇒ Object
convert from UpperCamelCase to lower_snake_case
5 6 7 8 9 |
# File 'lib/humidifier/utils.rb', line 5 def self.underscore(name) return nil unless name name.gsub(/([A-Z]+)([0-9]|[A-Z]|\z)/) { "#{$1.capitalize}#{$2}" } .gsub(/(.)([A-Z])/, '\1_\2').downcase end |
.underscored(names) ⇒ Object
a frozen hash of the given names mapped to their underscored version
12 13 14 |
# File 'lib/humidifier/utils.rb', line 12 def self.underscored(names) names.map { |name| [name, underscore(name).to_sym] }.to_h.freeze end |