Module: Rumoji

Extended by:
Rumoji
Included in:
Rumoji
Defined in:
lib/rumoji.rb,
lib/rumoji/emoji.rb,
lib/rumoji/version.rb,
lib/rumoji/emoji/nature.rb,
lib/rumoji/emoji/people.rb,
lib/rumoji/emoji/places.rb,
lib/rumoji/emoji/objects.rb,
lib/rumoji/emoji/symbols.rb

Defined Under Namespace

Classes: Emoji

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object

Transform a cheat-sheet code into an Emoji


19
20
21
# File 'lib/rumoji.rb', line 19

def decode(str)
  str.gsub(/:(\S?\w+):/) {|sym| Emoji.find($1.intern).to_s }
end

#decode_io(readable, writeable = StringIO.new("")) ⇒ Object


32
33
34
35
36
37
# File 'lib/rumoji.rb', line 32

def decode_io(readable, writeable=StringIO.new(""))
  readable.each_line do |line|
    writeable.write decode(line)
  end
  writeable
end

#encode(str) ⇒ Object

Transform emoji into its cheat-sheet code


10
11
12
13
14
15
16
# File 'lib/rumoji.rb', line 10

def encode(str)
  remapped_codepoints = str.codepoints.flat_map do |codepoint|
    emoji = Emoji.find_by_codepoint(codepoint)
    emoji ? emoji.code.codepoints.entries : codepoint
  end
  remapped_codepoints.pack("U*")
end

#encode_io(readable, writeable = StringIO.new("")) ⇒ Object


23
24
25
26
27
28
29
30
# File 'lib/rumoji.rb', line 23

def encode_io(readable, writeable=StringIO.new(""))
  readable.each_codepoint do |codepoint|
    emoji = Emoji.find_by_codepoint(codepoint)
    emoji_or_character = emoji ? emoji.code : [codepoint].pack("U")
    writeable.write emoji_or_character
  end
  writeable
end