Created
October 23, 2013 12:15
-
-
Save dannguyen/7117543 to your computer and use it in GitHub Desktop.
funny string cleaning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def astrip | |
self.gsub(/([\302|\240|\s|\n|\t])|(\ ?){1,}/, ' ').gsub("\240",' ').ostrip | |
end | |
def clean_chars | |
self.clean_dashes.clean_funny_spaces | |
end | |
def clean_dashes | |
self.gsub('‐', '-') | |
end | |
def clean_funny_spaces | |
self.gsub(/^[\302\240|\s]*|[\302\240|\s]*$/, '') | |
end | |
def ostrip | |
self.strip.gsub(/^[\302\240|\s]*|[\302\240|\s]*$/, '').gsub(/[\r\n]/, " ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment