refactor code to adhere to @bbhatsov's ruby style guide

* `rubocop —auto-correct`
* some parts of the code dealing with regex were not included because I
wasn’t entirely if Rails would work with it.