Module: NomenHelper

Defined in:
app/helpers/nomen_helper.rb

Constant Summary collapse

AVATARS_INDEX =
Rails.root.join('db', 'nomenclatures', 'avatars.yml').freeze
AVATARS =
(AVATARS_INDEX.exist? ? YAML.load_file(AVATARS_INDEX) : {}).freeze
COLORS_INDEX =
Rails.root.join('db', 'nomenclatures', 'colors.yml').freeze
COLORS =
(COLORS_INDEX.exist? ? YAML.load_file(COLORS_INDEX) : {}).freeze

Instance Method Summary collapse

Instance Method Details

#activity_avatar_path(activity) ⇒ Object


14
15
16
17
18
19
20
# File 'app/helpers/nomen_helper.rb', line 14

def activity_avatar_path(activity)
  if (variety = Nomen::Variety.find(activity.cultivation_variety))
    path = item_avatar_path(variety)
  end
  path ||= item_avatar_path Nomen::ActivityFamily.find(activity.family)
  path
end

#item_avatar_path(item) ⇒ Object


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

def item_avatar_path(item)
  nomenclature = AVATARS[item.nomenclature.table_name]
  return nil unless nomenclature
  item.rise { |i| nomenclature[i.name] }
end

#item_color(item) ⇒ Object


22
23
24
25
26
# File 'app/helpers/nomen_helper.rb', line 22

def item_color(item)
  nomenclature = COLORS[item.nomenclature.table_name]
  return nil unless nomenclature
  item.rise { |i| nomenclature[i.name] }
end

#variety_color(activity) ⇒ Object


28
29
30
31
32
33
34
# File 'app/helpers/nomen_helper.rb', line 28

def variety_color(activity)
  if (variety = Nomen::Variety.find(activity.cultivation_variety))
    path = item_color(variety)
  end
  path ||= item_color Nomen::ActivityFamily.find(activity.family)
  path
end