Tweaks and improvements

The main improvement is a small optimisation: reducing the number of calls to `gsub`.

I've also made a few minor improvements (well, I think they're improvements!):

* Use `module_function` to remove the need for `def self.foo` everywhere
* Make quoting consistent
* Swap branches to reduce negation (i.e. if cond/else instead of if !cond/else)
* Update the deprecated `:rubygems` gem source in the Gemfile