Module: TextCleaner
- Defined in:
- lib/facebook_word_counter/text_cleaner.rb
Constant Summary collapse
- FILLER_WORDS =
%w{ and the of as if is to in my a be will i ive are not my are not can out go am im for }
Class Method Summary collapse
- .clean_text(text) ⇒ Object
- .remove_filler_words(text) ⇒ Object
- .remove_punctuation(text) ⇒ Object
- .remove_urls(text) ⇒ Object
Class Method Details
.clean_text(text) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/facebook_word_counter/text_cleaner.rb', line 2 def self.clean_text(text) text = remove_urls(text.downcase) text = remove_punctuation(text) text = remove_filler_words(text) text.strip end |
.remove_filler_words(text) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/facebook_word_counter/text_cleaner.rb', line 18 def self.remove_filler_words(text) FILLER_WORDS.each do |word| text.gsub!(/ #{word} / , ' ') end text end |
.remove_punctuation(text) ⇒ Object
13 14 15 |
# File 'lib/facebook_word_counter/text_cleaner.rb', line 13 def self.remove_punctuation(text) text.gsub(/[^a-zA-Z\s]/, '') end |
.remove_urls(text) ⇒ Object
9 10 11 |
# File 'lib/facebook_word_counter/text_cleaner.rb', line 9 def self.remove_urls(text) text.gsub(/https?:\/\/[\S]+/, '') end |