# How to refactor this function to solve cyclomatic issue? [closed]

I'm trying to fix this error on codeclimate

Cyclomatic complexity for resource_icon is too high. [7/6]

What is the best way to refactor this function?

def resource_icon(resource)
case resource.to_sym
when :locations
'fa-building'
when :monitored_places
'fa-globe'
when :attendances
'fa fa-bicycle'
when :gym_distribuitions
'fa fa-users'
when :ranking_activities
'fa fa-list-ol'
when :attendance_by_group_class_trainers
else
'fa-diamond'
end
end


## closed as too broad by Graipher, Incomputable, Vogel612♦, alecxe, Jamal♦Oct 5 '17 at 0:47

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome to Code Review. Please explain how this code is to be used, in context. See How to Ask. – 200_success Oct 4 '17 at 14:58

• Indeed : h = {locations: 'fa-building', monitored_places: 'fa-globe', attendances: 'fa fa-bicycle', gym_distribuitions: 'fa fa-users', ranking_activities: 'fa fa-list-ol', attendance_by_group_class_trainers: 'fa fa-graduation-cap'}; h.default = 'fa-diamond'; h – Eric Duminil Oct 5 '17 at 12:00