module BrregGrunndata::Utils::StringExt

Constants

NAMESPACE_SEPARATOR
UNDERSCORE_DIVISION_TARGET
UNDERSCORE_SEPARATOR

Public Instance Methods

underscore() click to toggle source

Underscores a string

Taken from github.com/hanami/utils/blob/a2c9fe966ecc4e1997ffb616c7e57fc6e7acfadd/lib/hanami/utils/string.rb#L154-L175

# File lib/brreg_grunndata/utils.rb, line 85
def underscore
  new_string = gsub(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
  new_string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
  new_string.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
  new_string.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
  new_string.downcase!
  new_string
end