I have a method:
def assign_value ... @obj.value = find_value end
and a huge lookup table:
def find_value if @var > 0 && @var <= 30 0.4 elsif @var > 30 && @var <= 50 0.7 elsif @var > 50 && @var <= 70 1.1 elsif @var > 70 && @var <= 100 1.5 elsif @var > 100 && @var <= 140 2.10 elsif @var > 140 && @var <= 200 2.95 elsif @var > 200 && @var <= 300 4.35 elsif @var > 300 && @var <= 400 6.15 elsif @var > 400 && @var <= 500 7.85 elsif @var > 500 && @var <= 600 9.65 ... end
and so on for 1800 lines.
Needless to say, it's for the tax department of an unnamed country. Right now, it's written manually (all 1800 lines of it) to account the varying length of the integer ranges and decimal return values.
Without rewriting an entire country's tax code, how would I refactor this?
The ranges and values do change on a yearly basis, and we need to maintain backwards compatibility. A database table would simplify matters, but because we're dealing with a number of different countries, each with different requirements and tax codes, creating a database table isn't as straightforward as it sounds.