Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/utopia/extensions.rb
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
37 38 39 |
# File 'lib/utopia/extensions.rb', line 37 def to_html gsub(HTML_ESCAPE_PATTERN){|c| HTML_ESCAPE[c]} end |
#to_snake ⇒ Object
45 46 47 |
# File 'lib/utopia/extensions.rb', line 45 def to_snake self.gsub("::", "").gsub(/([A-Z]+)/){"_" + $1.downcase}.sub(/^_+/, "") end |
#to_title ⇒ Object
41 42 43 |
# File 'lib/utopia/extensions.rb', line 41 def to_title (" " + self).gsub(/[ \-_](.)/){" " + $1.upcase} end |