class String
Public Instance Methods
as_html()
click to toggle source
simple markdown
# File lib/overload/string.rb, line 7 def as_html self.gsub($/, '<br />') end
blank?()
click to toggle source
# File lib/overload/blank.rb, line 61 def blank? return true if self.length == 0 !(self =~ /[^\s]/) end
constantize()
click to toggle source
# File lib/overload/string.rb, line 2 def constantize Object.const_get('::'+self) end
css_to_hash()
click to toggle source
# File lib/overload/string.rb, line 58 def css_to_hash self.split('&').inject({}) do |h,line| el = line.split('=', 2) h[el[0]] = el[1] h end end
decolorize()
click to toggle source
remomove colorize gem string colors
# File lib/overload/string.rb, line 92 def decolorize self.gsub(/\[0;\d\d;\d\dm([^\[]*)\[0m/) { $1 } end
ends_with?(suffix)
click to toggle source
# File lib/overload/string.rb, line 74 def ends_with? suffix suffix.is_a?(String) && self[-suffix.length, suffix.length] == suffix && self != suffix end
escape()
click to toggle source
# File lib/overload/string.rb, line 96 def escape CGI::escape self end
first()
click to toggle source
# File lib/overload/string.rb, line 25 def first self[0,1] end
fix_ut8()
click to toggle source
# File lib/overload/string.rb, line 38 def fix_ut8 self.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '?') end
last(num=1)
click to toggle source
# File lib/overload/string.rb, line 78 def last(num=1) len = self.length self[len-num, len] end
parameterize()
click to toggle source
# File lib/overload/string.rb, line 46 def parameterize self.downcase.gsub(/[^\w]+/,'-') end
parse_erb()
click to toggle source
# File lib/overload/string.rb, line 42 def parse_erb self.gsub(/<%=([^%]+)%>/) { eval $1; } end
sanitize()
click to toggle source
# File lib/overload/string.rb, line 29 def sanitize Sanitize.clean(self, :elements=>%w[span ul ol li b bold i italic u underline hr br p], :attributes=>{'span'=>['style']} ) end
span_green()
click to toggle source
# File lib/overload/string.rb, line 83 def span_green %[<span style="color: #080;">#{self}</span>] end
span_red()
click to toggle source
# File lib/overload/string.rb, line 87 def span_red %[<span style="color: #800;">#{self}</span>] end
starts_with?(prefix)
click to toggle source
# File lib/overload/string.rb, line 70 def starts_with? prefix prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix end
string_id()
click to toggle source
# File lib/common/string_base.rb, line 46 def string_id StringBase.decode self end
to_a()
click to toggle source
# File lib/overload/string.rb, line 66 def to_a self.split(/\s*,\s*/) end
to_html(opts={})
click to toggle source
convert escaped strings, remove scritpts
# File lib/overload/string.rb, line 12 def to_html opts={} value = self.gsub(/</, '<').gsub(/>/, '>').gsub(/&/,'&') value = value.gsub(/<script/,'<script') unless opts[:script] value = value.gsub(/<link/,'<link') unless opts[:link] value end
to_url()
click to toggle source
# File lib/overload/string.rb, line 50 def to_url str_from = 'šđč枊ĐČĆŽäÄéeöÖüüÜß' str_to = 'sdcczSDCCZaAeeoOuuUs' str = self.downcase.gsub(/\s+/,'-').tr(str_from, str_to) # self.downcase.gsub(/\s+/,'-').tr(str_from, str_to).gsub(/[^\w\-]/,'') str.sub(/\.$/, '').gsub('&',' and ').gsub('.',' dot ').parameterize.gsub('-dot-','.').downcase[0, 50].sub(/[\.\-]$/,'') end
trim(len)
click to toggle source
# File lib/overload/string.rb, line 19 def trim(len) return self if self.length<len data = self.dup[0,len]+'…' data end
unescape()
click to toggle source
# File lib/overload/string.rb, line 100 def unescape CGI::unescape self end
wrap(node_name, opts={})
click to toggle source
# File lib/overload/string.rb, line 33 def wrap node_name, opts={} return self unless node_name opts.tag(node_name, self) end