Module: Emojimmy

Defined in:
lib/emojimmy.rb,
lib/emojimmy/mixin.rb,
lib/emojimmy/version.rb

Defined Under Namespace

Modules: Mixin

Constant Summary collapse

VERSION =
'0.3'

Class Method Summary collapse

Class Method Details

.emoji_to_token(content) ⇒ Object

Loop through all emoji and replace them with their matching token



15
16
17
18
19
20
21
22
23
# File 'lib/emojimmy.rb', line 15

def self.emoji_to_token(content)
  return content unless content.present?

  # Encode the string with Rumoji
  content = Rumoji.encode(content)

  # Return the text without any other weird characters
  Emojimmy.strip(content)
end

.strip(content) ⇒ Object

Loop through each character in the string and remove the all emoji ones



35
36
37
38
39
40
41
42
# File 'lib/emojimmy.rb', line 35

def self.strip(content)
  return content unless content.present?

  content.chars.select do |c|
    point = c.each_codepoint.to_a.first
    point <= 65535
  end.join
end

.token_to_emoji(content) ⇒ Object

Loop through each U+… token in the string and convert it to the matching emoji



27
28
29
30
31
# File 'lib/emojimmy.rb', line 27

def self.token_to_emoji(content)
  return content unless content.present?

  Rumoji.decode(content)
end