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
    when :monitored_places
    when :attendances
      'fa fa-bicycle'
    when :gym_distribuitions
      'fa fa-users'
    when :ranking_activities
      'fa fa-list-ol'
    when :attendance_by_group_class_trainers
      'fa fa-graduation-cap'

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.

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

You could try using a hash that maps "locations" to "fa-building", "monitored_places" to "fa-globe", and so on, with a default value of "fa-diamond".

  • 3
    \$\begingroup\$ 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 \$\endgroup\$ – Eric Duminil Oct 5 '17 at 12:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.