module Object::CampTools
Public Class Methods
descape()
click to toggle source
A Regex to descape escaped characters. used to correct URLs that are escpaed using Rack Util’s escape function.
# File lib/camping/tools.rb, line 34 def descape /\\(.)/ end
normalize_slashes(string)
click to toggle source
Normalize Slashes normalizes the leading and trailing slashes of a string to only have a single trailing slash and no leading slashes.
# File lib/camping/tools.rb, line 22 def normalize_slashes(string) f = string.dup return "" if f == "" # Short circuit for blank prefixes. f.chop!until f[-1] != "/" f.slice!(0)until f[0] != "/" f << "/" end
Also aliased as: norms
to_snake(string)
click to toggle source
to_snake Accepts a string and snake Cases it. Also accepts symbols and coerces them into a string.
# File lib/camping/tools.rb, line 10 def to_snake(string) string = string.to_s if string.class == Symbol string.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end