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 sure if Rails would work with it.