Method: Stringex::StringExtensions::PublicInstanceMethods#to_url

Defined in:
lib/stringex/string_extensions.rb

#to_url(options = {}) ⇒ Object

Create a URI-friendly representation of the string. This is used internally by acts_as_url but can be called manually in order to generate an URI-friendly version of any string.



191
192
193
194
195
196
197
198
199
200
201
# File 'lib/stringex/string_extensions.rb', line 191

def to_url(options = {})
  return self if options[:exclude] && options[:exclude].include?(self)
  options = stringex_default_options.merge(options)
  whitespace_replacement_token = options[:replace_whitespace_with]
  dummy = remove_formatting(options).
            replace_whitespace(whitespace_replacement_token).
            collapse(whitespace_replacement_token).
            limit(options[:limit], options[:truncate_words], whitespace_replacement_token)
  dummy.downcase! unless options[:force_downcase] == false
  dummy
end