If you want, the needed input cases and their desired output forms are in the repo, I would love to see how it's done in Ruby.
https://github.com/2grep/CoPATH-Parser
I'm not completely wed to postgresql, but I would hate to give up Joe, who has been tremendously helpful. And most of my admin experience is with postgresql (blogs, wikis, etc).