Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/extensions.rb

Constant Summary collapse

HTML_ESCAPE =
{"&" => "&amp;", "<" => "&lt;", ">" => "&gt;", "\"" => "&quot;"}
HTML_ESCAPE_PATTERN =
Regexp.new("[" + Regexp.quote(HTML_ESCAPE.keys.join) + "]")

Instance Method Summary collapse

Instance Method Details

#to_htmlObject



37
38
39
# File 'lib/utopia/extensions.rb', line 37

def to_html
	gsub(HTML_ESCAPE_PATTERN){|c| HTML_ESCAPE[c]}
end

#to_snakeObject



45
46
47
# File 'lib/utopia/extensions.rb', line 45

def to_snake
	self.gsub("::", "").gsub(/([A-Z]+)/){"_" + $1.downcase}.sub(/^_+/, "")
end

#to_titleObject



41
42
43
# File 'lib/utopia/extensions.rb', line 41

def to_title
	(" " + self).gsub(/[ \-_](.)/){" " + $1.upcase}
end