I have some methods in my model which I use to access stored text hashes in my views:
class CarSpec < ActiveRecord::Base
@@fuel_type_select_data = Hash[(1..5).to_a.zip(['Petrol', 'Diesel', 'Gas/petrol', 'Hybrid', 'Electric'])]
@@mileage_type_select_data = Hash[(1..2).to_a.zip(['km', 'miles'])]
@@transmission_select_data = Hash[(1..3).to_a.zip(['Manual', 'Automatic', 'Tiptronic'])]
@@wheel_drive_data = Hash[(1..3).to_a.zip(['Front', 'Rear', 'All'])]
@@color_data = Hash[(1..8).to_a.zip(['black', 'white', 'beige',
'blue', 'yellow', 'green', 'red', 'silver'])]
def text_for_fuel_type
@@fuel_type_select_data[fuel_type]
end
def text_for_mileage_type
@@mileage_type_select_data[mileage_type]
end
def text_for_transmission
@@transmission_select_data[transmission]
end
def text_for_wheel_drive
@@wheel_drive_data[wheel_drive]
end
def text_for_color
@@color_data[color]
end
def text_for_interior_color
@@color_data[interior_color]
end
Currently, I need to write a new method for every field. How can I refactor these methods, so that I do not need to write a new method for each field? Please include how the new method/s would be called in the view.