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.5.0"

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object

Transform a cheat-sheet code into an Emoji



15
16
17
# File 'lib/rumoji.rb', line 15

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

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



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

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
# File 'lib/rumoji.rb', line 10

def encode(str)
  str.gsub(Emoji::ALL_REGEXP) { |match| (emoji = Emoji.find_by_string(match)) && emoji.code || match }
end

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



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

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