engines/adva_cms/vendor/plugins/stringex/lib/lucky_sneaks/string_extensions.rb
def convert_misc_characters
      dummy = dup.gsub(/\.{3,}/, " dot dot dot ") # Catch ellipses before single dot rule!
      # Special rules for money
      {
        /(\s|^)\$(\d+)\.(\d+)(\s|$)/ => '\2 dollars \3 cents',
        /(\s|^)£(\d+)\.(\d+)(\s|$)/u => '\2 pounds \3 pence',
      }.each do |found, replaced|
        replaced = " #{replaced} " unless replaced =~ /\\1/
        dummy.gsub!(found, replaced)
      end
      # Back to normal rules
      {
        /\s*&\s*/ => "and",
        /\s*#/ => "number",
        /\s*@\s*/ => "at",
        /(\S|^)\.(\S)/ => '\1 dot \2',
        /(\s|^)\$(\d*)(\s|$)/ => '\2 dollars',
        /(\s|^)£(\d*)(\s|$)/u => '\2 pounds',
        /(\s|^)¥(\d*)(\s|$)/u => '\2 yen',
        /\s*\*\s*/ => "star",
        /\s*%\s*/ => "percent",
        /\s*(\\|\/)\s*/ => "slash",
      }.each do |found, replaced|
        replaced = " #{replaced} " unless replaced =~ /\\1/
        dummy.gsub!(found, replaced)
      end
      dummy = dummy.gsub(/(^|\w)'(\w|$)/, '\1\2').gsub(/[\.,:;()\[\]\/\?!\^'"_]/, " ")
    end
# 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"
#   
# Note: Because this method will convert any & symbols to the string "and",
# you should run any methods which convert HTML entities (convert_html_entities and convert_misc_entities)
# before running this method.
Converts various common plaintext characters to a more URI-friendly representation.
Examples.



Because this method will convert any & symbols to the string "and",
you should run any methods which convert HTML entities (convert_html_entities and convert_misc_entities)
before running this method.
Converts various common plaintext characters to a more URI - friendly representation . Examples . Because this method will convert any & symbols to the string " and " you should run any methods which convert HTML entities ( convert_html_entities and convert_misc_entities ) before running this method .
def convert_misc_characters
      dummy = dup.gsub(/\.{3,}/, " dot dot dot ") 
      {
        /(\s|^)\$(\d+)\.(\d+)(\s|$)/ => '\2 dollars \3 cents',
        /(\s|^)£(\d+)\.(\d+)(\s|$)/u => '\2 pounds \3 pence',
      }.each do |found, replaced|
        replaced = " #{replaced} " unless replaced =~ /\\1/
        dummy.gsub!(found, replaced)
      end
      {
        /\s*&\s*/ => "and",
        /\s*#/ => "number",
        /\s*@\s*/ => "at",
        /(\S|^)\.(\S)/ => '\1 dot \2',
        /(\s|^)\$(\d*)(\s|$)/ => '\2 dollars',
        /(\s|^)£(\d*)(\s|$)/u => '\2 pounds',
        /(\s|^)¥(\d*)(\s|$)/u => '\2 yen',
        /\s*\*\s*/ => "star",
        /\s*%\s*/ => "percent",
        /\s*(\\|\/)\s*/ => "slash",
      }.each do |found, replaced|
        replaced = " #{replaced} " unless replaced =~ /\\1/
        dummy.gsub!(found, replaced)
      end
      dummy = dummy.gsub(/(^|\w)'(\w|$)/, '\1\2').gsub(/[\.,:;()\[\]\/\?!\^'"_]/, " ")
    end
def convert_misc_characters dummy = dup . gsub ( / \. {3,} / , " dot dot dot " ) { / ( \s |^) \$ ( \d +) \. ( \d +)( \s |$) / => '\2 dollars \3 cents' , / ( \s |^)£(\ d+ )\ .( \ d+ )(\ s| $)/ u  >  \2 pounds \3 pence', } . each do | found , replaced | replaced = " #{replaced} " unless replaced =~ / \\ 1 / dummy . gsub! ( found , replaced ) end { / \s *& \s * / => "and" , / \s *# / => "number" , / \s *@ \s * / => "at" , / ( \S |^) \. ( \S ) / => '\1 dot \2' , / ( \s |^) \$ ( \d *)( \s |$) / => '\2 dollars' , / ( \s |^)£(\ d* )(\ s| $)/ u  >  \2 pounds', / ( \s |^)¥(\ d* )(\ s| $)/ u  >  \2 yen', / \s * \* \s * / => "star" , / \s *% \s * / => "percent" , / \s *( \\ | \/ ) \s * / => "slash" , } . each do | found , replaced | replaced = " #{replaced} " unless replaced =~ / \\ 1 / dummy . gsub! ( found , replaced ) end dummy = dummy . gsub ( / (^| \w )'( \w |$) / , '\1\2' ) . gsub ( / [ \. ,:;() \[ \] \/ \? ! \^ '"_] / , " " ) end
Converts various common plaintext characters to a more URI-friendly representation.
Converts various common plaintext characters to a more URI - friendly representation .
# Catch ellipses before single dot rule! # Special rules for money # Back to normal rules