Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Constant Summary collapse

DISALLOWED_CHARACTERS =
"[\-\s\.\,\?\'\"\:\;\\\/]"

Instance Method Summary collapse

Instance Method Details

#humanizeObject



4
5
6
# File 'lib/core_ext/string.rb', line 4

def humanize
  gsub(DISALLOWED_CHARACTERS, " ").split(" ").map(&:capitalize).join("")
end

#sanitizeObject



14
15
16
# File 'lib/core_ext/string.rb', line 14

def sanitize
  gsub(DISALLOWED_CHARACTERS, "_")
end

#underscoreObject



8
9
10
11
12
# File 'lib/core_ext/string.rb', line 8

def underscore
  u = ""
  sanitize.split("").each_with_index do |c, i|; if i > 0 && c == c.upcase; u += " "; end; u += c.downcase; end;
  u.gsub(" ", "_")
end