Refracting ruby logic into CQL.