I am currently working on a small internal rating system for clients to be able to prioritise my work based on what client pays best. The input data is the hourly rate they are paying and based on that they should be divided into categories in are the range from A-D. The first setup looks like this:
def category_for(client)
hourly_rate = client.hourly_rate
case client.country
when :germany
return 'A' if hourly_rate >= 35
return 'B' if hourly_rate >= 30
return 'C' if hourly_rate >= 25
return 'D' if hourly_rate < 25
when :sweden
return 'A' if hourly_rate >= 400
return 'B' if hourly_rate >= 350
return 'C' if hourly_rate >= 300
return 'D' if hourly_rate < 300
end
end
This is ofc only part of it to show the general setup.
This code, although working fine, really really hurts my eyes, so I was wondering if someone here had a good idea on how to refactor it in a nice way?