Refactor 10-lines switch into ternary if.