# -*- encoding: utf-8 -*-
require "rumoji/version"
require "rumoji/emoji"
require 'stringio'

module Rumoji
  extend self

  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

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

  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

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

end

# -*- encoding: utf-8 -*-
require "rumoji/version"
require "rumoji/emoji"
require 'stringio'

module Rumoji
  extend self

  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

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

  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

  def decode_io(readable, writeable=StringIO.new(""))
    readable.each_line do |line|
      writeable.write line.gsub(/:(\w+):/) {|sym| Emoji.find($1.intern).to_s }
    end
    writeable
  end

  def codepoint_as_hex(codepoint)
    codepoint.to_s(16).upcase
  end

end

--- 
+++ 
@@ -15,7 +15,7 @@
   end
 
   def decode(str)
-    str.gsub(/:(\w+):/) {|sym| Emoji.find($1.intern).to_s }
+    str.gsub(/:(\S?\w+):/) {|sym| Emoji.find($1.intern).to_s }
   end
 
   def encode_io(readable, writeable=StringIO.new(""))
@@ -29,13 +29,9 @@
 
   def decode_io(readable, writeable=StringIO.new(""))
     readable.each_line do |line|
-      writeable.write line.gsub(/:(\w+):/) {|sym| Emoji.find($1.intern).to_s }
+      writeable.write decode(line)
     end
     writeable
   end
 
-  def codepoint_as_hex(codepoint)
-    codepoint.to_s(16).upcase
-  end
-
 end
Make emoji code pattern more permissive (to allow for :+1:)
