Sha256: 41b4a81a3b9cf6e3a28c53800abef17bf8a6a6a3f285f39ce8a9aa3d3f9840f1

Contents?: true

Size: 479 Bytes

Versions: 2

Compression:

Stored size: 479 Bytes

Contents

# frozen_string_literal: true

require 'gemoji'

module AutoHtml
  # Emoji filter
  class Emoji
    def call(text)
      text.gsub(self.class.emoji_pattern) do
        name = Regexp.last_match(1)
        ::Emoji.find_by_alias(name).raw
      end
    end

    def self.emoji_pattern
      @emoji_pattern ||=
        /:(#{emoji_names.map { |name| Regexp.escape(name) }.join('|')}):/
    end

    def self.emoji_names
      ::Emoji.all.map(&:aliases).flatten.sort
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auto_html-2.1.1 lib/auto_html/emoji.rb
auto_html-2.1.0 lib/auto_html/emoji.rb