lib/pretty_strings.rb in pretty_strings-0.1.0 vs lib/pretty_strings.rb in pretty_strings-0.2.0

- old
+ new

@@ -8,11 +8,12 @@ @text = text end def pretty return '' if text.nil? || text.empty? - replace_symbol_with_bracket( + remove_bracketed_numbers( + replace_symbol_with_bracket( remove_newlines( replace_tabs( remove_bracketed_code( scan_for_code( escape_text( @@ -20,11 +21,11 @@ replace_bracket_with_symbol( escape_text( sanitize_text( replace_bracket_with_symbol( text - ))))))))))).squeeze(" ").strip + )))))))))))).squeeze(" ").strip end private def remove_newlines(text) @@ -35,18 +36,32 @@ def replace_tabs(text) text.gsub!(/\t/, ' ') || text end def remove_bracketed_code(text) + text.gsub!(/(?<=\*\*)\{(?=date\}\*\*)/, '⚘') || text + text.gsub!(/(?<=\*\*)\{(?=number\}\*\*)/, '⚘') || text + text.gsub!(/(?<=\*\*)\{(?=email\}\*\*)/, '⚘') || text + text.gsub!(/(?<=\*\*)\{(?=url\}\*\*)/, '⚘') || text + text.gsub!(/(?<=\*\*\{date)\}(?=\*\*)/, '♚') || text + text.gsub!(/(?<=\*\*\{number)\}(?=\*\*)/, '♚') || text + text.gsub!(/(?<=\*\*\{email)\}(?=\*\*)/, '♚') || text + text.gsub!(/(?<=\*\*\{url)\}(?=\*\*)/, '♚') || text text.gsub!(/\{.*?\}/, '') || text + text.gsub!(/♚/, '}') || text + text.gsub!(/⚘/, '{') || text end def replace_bracket_with_symbol(text) text.gsub!(/<(?=\s*\d+)/, '♳') || text end def replace_symbol_with_bracket(text) text.gsub!(/♳/, '<') || text + end + + def remove_bracketed_numbers(text) + text.gsub!(/\<\d+\>/, '') || text end def escape_text(text) CGI.unescapeHTML(CGI.unescapeHTML(CGI.unescapeHTML(CGI.unescapeHTML(text)))) end