Port Ruby code to unit chooser