lib/bhm/utils.rb
# Transform a stringified module to an accessible hash key
# Assume we want symbols by default
Transform a stringified module to an accessible hash key
Assume we want symbols by default
Transform a stringified module to an accessible hash key Assume we want symbols by default
def transform_module_casing(module_name, key_casing, key_type)
      transformed_module = case key_casing
      when :lower_snake
        module_name.to_s.gsub(/[A-Z]/) { |mtch| "_" + mtch.downcase }.sub(/^_/, "")
      when :lowerCamel
        module_name.to_s.sub(/^./) { |first_char| first_char.downcase }
      when :UpperCamel
        module_name.to_s
      when :SCREAMING_SNAKE
        module_name.to_s.gsub(/[A-Z]/) { |mtch| "_" + mtch }.upcase.sub(/^_/, "")
      else
        fail ArgumentError, "invalid casing provided: #{key_casing.inspect}"
      end
      key_type ||= :symbols
      transformed_module = transformed_module.to_sym if key_type == :symbols
      transformed_module
    end
def transform_module_casing ( module_name , key_casing , key_type ) transformed_module = case key_casing when :lower_snake module_name . to_s . gsub ( / [A-Z] / ) { | mtch | "_" + mtch . downcase } . sub ( / ^_ / , "" ) when :lowerCamel module_name . to_s . sub ( / ^. / ) { | first_char | first_char . downcase } when :UpperCamel module_name . to_s when :SCREAMING_SNAKE module_name . to_s . gsub ( / [A-Z] / ) { | mtch | "_" + mtch } . upcase . sub ( / ^_ / , "" ) else fail ArgumentError , "invalid casing provided: #{key_casing.inspect}" end key_type ||= :symbols transformed_module = transformed_module . to_sym if key_type == :symbols transformed_module end
Transform a stringified module to an accessible hash key
Assume we want symbols by default
Transform a stringified module to an accessible hash key Assume we want symbols by default
# Coerce into symbols if key_type was explicitly passed as `nil`
module_name
<not_specific>
key_casing
<not_specific>
key_type
<not_specific>