BigW Consortium Gitlab

award_emoji.rb 1.13 KB
Newer Older
Valery Sizov committed
1
class AwardEmoji
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  CATEGORIES = {
    other: "Other",
    objects: "Objects",
    places: "Places",
    travel_places: "Travel",
    emoticons: "Emoticons",
    objects_symbols: "Symbols",
    nature: "Nature",
    celebration: "Celebration",
    people: "People",
    activity: "Activity",
    flags: "Flags",
    food_drink: "Food"
  }.with_indifferent_access

Valery Sizov committed
17
  def self.normilize_emoji_name(name)
18
    aliases[name] || name
Valery Sizov committed
19
  end
20 21 22 23 24

  def self.emoji_by_category
    unless @emoji_by_category
      @emoji_by_category = {}

25 26
      emojis.each do |emoji_name, data|
        data["name"] = emoji_name
27 28 29 30 31 32 33 34 35 36

        @emoji_by_category[data["category"]] ||= []
        @emoji_by_category[data["category"]] << data
      end

      @emoji_by_category = @emoji_by_category.sort.to_h
    end

    @emoji_by_category
  end
37 38 39 40 41 42 43 44 45 46 47 48 49 50

  def self.emojis
    @emojis ||= begin
      json_path = File.join(Rails.root, 'fixtures', 'emojis', 'index.json' )
      JSON.parse(File.read(json_path))
    end
  end

  def self.aliases
    @aliases ||= begin
      json_path = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json' )
      JSON.parse(File.read(json_path))
    end
  end
Valery Sizov committed
51
end