Class: String
Overview
This file is part of the “Utopia Framework” project, and is released under the MIT license. Copyright 2010 Samuel Williams. All rights reserved. See <utopia.rb> for licensing details.
Constant Summary collapse
- HTML_ESCAPE =
{"&" => "&", "<" => "<", ">" => ">", "\"" => """}
- HTML_ESCAPE_PATTERN =
Regexp.new("[" + Regexp.quote(HTML_ESCAPE.keys.join) + "]")
Instance Method Summary collapse
Instance Method Details
#to_html ⇒ Object
9 10 11 |
# File 'lib/utopia/extensions/string.rb', line 9 def to_html gsub(HTML_ESCAPE_PATTERN){|c| HTML_ESCAPE[c]} end |
#to_quoted_string ⇒ Object
13 14 15 |
# File 'lib/utopia/extensions/string.rb', line 13 def to_quoted_string '"' + self.gsub('"', '\\"').gsub(/\r/, "\\r").gsub(/\n/, "\\n") + '"' end |
#to_snake ⇒ Object
21 22 23 |
# File 'lib/utopia/extensions/string.rb', line 21 def to_snake self.gsub("::", "").gsub(/([A-Z]+)/){"_" + $1.downcase}.sub(/^_+/, "") end |
#to_title ⇒ Object
17 18 19 |
# File 'lib/utopia/extensions/string.rb', line 17 def to_title self.gsub(/(^|[ \-_])(.)/){" " + $2.upcase}.strip end |