Module: Humidifier::Utils

Defined in:
lib/humidifier/utils.rb

Overview

Dumps an object to CFN syntax

Class Method Summary collapse

Class Method Details

.underscore(name) ⇒ Object

convert from UpperCamelCase to lower_snake_case



7
8
9
10
11
12
# File 'lib/humidifier/utils.rb', line 7

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



15
16
17
# File 'lib/humidifier/utils.rb', line 15

def self.underscored(names)
  names.map { |name| [name, underscore(name).to_sym] }.to_h.freeze
end