Move code out of rake file and into class