Method: Stringex::StringExtensions::PublicInstanceMethods#convert_miscellaneous_characters
- Defined in:
- lib/stringex/string_extensions.rb
#convert_miscellaneous_characters(options = {}) ⇒ Object
Converts various common plaintext characters to a more URI-friendly representation. Examples:
"foo & bar".convert_misc_characters # => "foo and bar"
"Chanel #9".convert_misc_characters # => "Chanel number nine"
"user@host".convert_misc_characters # => "user at host"
"google.com".convert_misc_characters # => "google dot com"
"$10".convert_misc_characters # => "10 dollars"
"*69".convert_misc_characters # => "star 69"
"100%".convert_misc_characters # => "100 percent"
"windows/mac/linux".convert_misc_characters # => "windows slash mac slash linux"
It allows localization of conversions so you can use it to convert characters into your own language. Example:
I18n.backend.store_translations :de, { :stringex => { :characters => { :and => "und" } } }
I18n.locale = :de
"ich & dich".convert_misc_characters # => "ich und dich"
Note: Because this method will convert any & symbols to the string “and”, you should run any methods which convert HTML entities (convert_accented_html_entities and convert_miscellaneous_html_entities) before running this method.
62 63 64 65 66 67 68 |
# File 'lib/stringex/string_extensions.rb', line 62 def convert_miscellaneous_characters( = {}) stringex_convert() do normalize_currency! translate! :ellipses, :currencies, :abbreviations, :characters, :apostrophes cleanup_characters! end end |