Module: TagSubstitutionHelper

Defined in:
app/helpers/tag_substitution_helper.rb

Overview

Provides methods mainly geared up to handle the display of tags and tag groups

Instance Method Summary collapse

Instance Method Details

#tag_name(tag_id) ⇒ Object

Returns a user friendly name for the corresponding tag



8
9
10
11
12
# File 'app/helpers/tag_substitution_helper.rb', line 8

def tag_name(tag_id)
  return 'Untagged' if tag_id == Aliquot::UNASSIGNED_TAG

  @complete_tags.dig(tag_id.to_i, 0)
end

#tag_options_for(tag_id) ⇒ Object



14
15
16
17
18
# File 'app/helpers/tag_substitution_helper.rb', line 14

def tag_options_for(tag_id)
  return { 'No group' => [['Untagged', Aliquot::UNASSIGNED_TAG]] } if tag_id == Aliquot::UNASSIGNED_TAG

  tags_in_groups.slice(@complete_tags.fetch(tag_id.to_i).last)
end

#tags_in_groupsObject



20
21
22
23
24
25
26
# File 'app/helpers/tag_substitution_helper.rb', line 20

def tags_in_groups
  @tags_in_groups ||=
    @complete_tags.each_with_object({}) do |(_id, info), store|
      store[info.last] ||= []
      store[info.last] << info[0, 2]
    end
end