Method: Hanami::Utils::String.underscore
- Defined in:
- lib/hanami/utils/string.rb
.underscore(input) ⇒ ::String
Returns a downcased and underscore separated version of the string
Revised version of ActiveSupport::Inflector.underscore implementation
228 229 230 231 232 233 234 235 236 |
# File 'lib/hanami/utils/string.rb', line 228 def self.underscore(input) string = ::String.new(input.to_s) string.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR) string.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR) string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET) string.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET) string.gsub!(/[[:space:]]|-|\./, UNDERSCORE_DIVISION_TARGET) string.downcase end |