class String
Re-open String
class and add snakecase method.
Public Instance Methods
ams_layout_snakecase()
click to toggle source
# File lib/ams_layout/core_ext/string.rb, line 13 def ams_layout_snakecase # Strip everything but alphanumerics, :, _, - and space # Replace :: with / # Separate CamelCased text with _ # Remove : # Replace space and - with _ # Replace multiple _ with one _ self.gsub(/[^a-zA-Z0-9:_\s-]/, ''). gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). gsub(/:/, ''). gsub(/[\s-]/, '_'). gsub(/(_)+/,'_'). downcase end