Class: ActiveCleaner::MarkdownCleaner
- Inherits:
-
BaseCleaner
- Object
- BaseCleaner
- ActiveCleaner::MarkdownCleaner
- Defined in:
- lib/active_cleaner/markdown_cleaner.rb
Instance Attribute Summary
Attributes inherited from BaseCleaner
Instance Method Summary collapse
Methods inherited from BaseCleaner
#==, #clean, #initialize, kind, #kind, #nilify_value?
Constructor Details
This class inherits a constructor from ActiveCleaner::BaseCleaner
Instance Method Details
#clean_value(old_value, record = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_cleaner/markdown_cleaner.rb', line 6 def clean_value(old_value, record=nil) unless old_value.nil? value = old_value.dup value.strip! # clean the new lines mess among OS value.gsub!(/\r\n|\r/, "\n") # protect stuff to keep with a markup value.gsub!(/\n/, "__NEW_LINE__") value.gsub!(/(?<=__NEW_LINE__)\s+/) {|match| match.gsub(/\s/, "__SPACE__")} value.gsub!(/\s+/, " ") value.gsub!(/(__SPACE__|\s)*__NEW_LINE__\s*/, "__NEW_LINE__") value.gsub!(/(__NEW_LINE__){3,}/, "__NEW_LINE____NEW_LINE__") # reverse the safe markup value.gsub!(/__NEW_LINE__/, "\n") value.gsub!(/__SPACE__/, " ") value end end |