Remove duplicate code

I found some code duplication listed on https://codeclimate.com/github/bbatsov/rubocop/issues/categories/duplication that was easy to fix. 

I have also directly added tests for `text_utils.rb`.