refactor ruby code and add first rspec unit test