Initial Ruby version. API mirrors that of original javascript.

Includes tests.