Method: ZohoHub::StringUtils.underscore

Defined in:
lib/zoho_hub/string_utils.rb

.underscore(text) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/zoho_hub/string_utils.rb', line 26

def underscore(text)
  return text unless text =~ /[A-Z-]/

  result = text.dup
  result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  result.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  result.tr!('-', '_')
  result.downcase!
  result
end