class EmojiReplace::Replacer
Attributes
text[R]
Public Class Methods
new(args)
click to toggle source
# File lib/emoji_replace/replacer.rb, line 4 def initialize(args) @text = args.fetch(:text).dup @index = Emoji::Index.new end
Public Instance Methods
back(args = {})
click to toggle source
# File lib/emoji_replace/replacer.rb, line 18 def back(args = {}) @text.gsub!(/%\{emoji:(.+?)\}/) do |moji_str| match = moji_str.match(/%\{emoji:(.+?)\}/) moji_name = match[1] moji = @index.find_by_name(moji_name) if args[:html] "<img alt=\"#{moji.fetch("name")}\" class=\"emoji\" src=\"#{Emoji.image_url_for_name(moji_name)}\">" else moji.fetch("moji") end end return self end
replace()
click to toggle source
# File lib/emoji_replace/replacer.rb, line 9 def replace @text.gsub!(@index.unicode_moji_regex) do |moji| moji = @index.find_by_moji(moji) "%{emoji:#{moji.fetch('name')}}" end return self end