Module: Aitextcleaner::FormattingResidue
- Defined in:
- lib/aitextcleaner/formatting_residue.rb
Constant Summary collapse
- BLOCK_TAG =
/<\/?(?:address|article|blockquote|br|div|li|p|pre|section)\b[^>]*>/i- HTML_TAG =
/<[^>]*>/
Class Method Summary collapse
Class Method Details
.clean(text) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/aitextcleaner/formatting_residue.rb', line 10 def clean(text) raise TypeError, "text must be a string" unless text.is_a?(String) cleaned = text.gsub(BLOCK_TAG, "\n").gsub(HTML_TAG, "") cleaned = CGI.unescapeHTML(cleaned) cleaned = cleaned.gsub("“", '"').gsub("”", '"').gsub("‘", "'").gsub("’", "'") .gsub("–", "-").gsub("—", "-").gsub("…", "...") cleaned.gsub(/[ \t]+\n/, "\n").gsub(/\n{3,}/, "\n\n").strip end |