Initial Ruby version. API mirrors that of original javascript, includes tests.