./lib/overload/string.rb in lux-fw-0.2.3 vs ./lib/overload/string.rb in lux-fw-0.5.32

- old
+ new

@@ -1,6 +1,10 @@ class String + def constantize + Object.const_get('::'+self) + end + # simple markdown def as_html self.gsub($/, '<br />') end @@ -16,19 +20,19 @@ return self if self.length<len data = self.dup[0,len]+'&hellip;' data end + def first + self[0,1] + end + def sanitize Sanitize.clean(self, :elements=>%w[span ul ol li b bold i italic u underline hr br p], :attributes=>{'span'=>['style']} ) end - def tag(node_name, opts={}) - opts.tag(node_name, self) - end - - def wrap(node_name, opts={}) + def wrap node_name, opts={} return self unless node_name opts.tag(node_name, self) end def fix_ut8 @@ -61,14 +65,18 @@ def to_a self.split(/\s*,\s*/) end - def starts_with?(prefix) + def starts_with? prefix prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix end + def ends_with? suffix + suffix.is_a?(String) && self[-suffix.length, suffix.length] == suffix && self != suffix + end + def last(num=1) len = self.length self[len-num, len] end @@ -81,7 +89,15 @@ end # remomove colorize gem string colors def decolorize self.gsub(/\[0;\d\d;\d\dm([^\[]*)\[0m/) { $1 } + end + + def escape + CGI::escape self + end + + def unescape + CGI::unescape self end end