It looks like lines 19-21 are responsible for killing whitespace in the rules. If that's correct, String has a method, [`strip`](http://www.ruby-doc.org/core-1.9.3/String.html#method-i-strip), which will do this for you.  This block (which is a little convoluted) can be changed to `rules.map(&:strip)`.

I will say that `strip` will remove tabs, newlines, and other whitespace as well, some of which `\s` isn't doing now. I'm pretty sure you are iterating by line at this point, so that should be okay.