Sha256: 5cea1165f35535c24b60e47d944a7a0f1e6fe749f3649bdc0a2db2e8b1037e1d
Contents?: true
Size: 865 Bytes
Versions: 8
Compression:
Stored size: 865 Bytes
Contents
class String # Return a string that can be used as part of a url # replaces basic "bad" characters with "-" def to_url self.downcase.gsub(/[^\-0-9a-z ]/, '').split.join('-') end # Truncates a string to the specified length, # and appends suffix if required # # Options: # * +length+ length to truncate string to. Includes the suffix in the length. Default is 50. # * +suffix+ suffix to append to truncated string. Pass "" or false for no suffix. Default is "...". # def truncate opts = {} opts[:length] ||= 50 opts[:suffix] = opts.has_key?(:suffix) ? opts[:suffix] : "..." opts[:suffix] ||= "" opts[:length] -= (opts[:suffix].length+1) if opts[:length] > 0 self.length > opts[:length] ? self[0..opts[:length]] + opts[:suffix] : self else opts[:suffix][0..(opts[:length] += opts[:suffix].length)] end end end
Version data entries
8 entries across 8 versions & 3 rubygems