emojimmy 0.1.1 β†’ 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddff8b1900275b1b84108e6c5618684c1b83960a
4
- data.tar.gz: bb3395a5113d4da945df785e92d4ddcb0d5cedb6
3
+ metadata.gz: 537d4a671f8d4f03de4905c27435d57b53d9b72b
4
+ data.tar.gz: 262e130bc35f71d5d0a33d38094a7b9aa3ed92ee
5
5
  SHA512:
6
- metadata.gz: 3a64f89dfcc71793fab9043b9d9832580762ee7516ccb8389f160af966279efcac2637ddc3f6b63a2e97ec239657b380e9e47e0bce972b69ad427d1e030f15ee
7
- data.tar.gz: d3731889f19f1a9d9bea442bbaa0c7e56b2590977d1e681cf15be144ef7cb29b40b9b14c4b9e6718ca3ddd892dea712e2af17cedebef9828b0fe2f95b6687342
6
+ metadata.gz: 13be2c19665b325c30b618df13053418294c8cafb0f91afde16252e3ac15bf45e9a3616b28b08cdd4d477371831a7666ac32ed32c6ffa160d7b9036ceea31030
7
+ data.tar.gz: 210b4ecd796feb3b7cdd1b4c02450502c9131d358c7161a11e5708d6e02fe87faecb92980e58088b072b8ef4f02ce11a7bc64ca4f5b1e6fe86c42c02a0db4935
data/lib/emojimmy.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'emojimmy/version'
2
3
 
3
4
  # Dependencies
@@ -7,20 +8,13 @@ require 'active_record'
7
8
  require 'emojimmy/mixin'
8
9
 
9
10
  module Emojimmy
11
+ DATA_FILE = File.expand_path('../../data/emoji.txt', __FILE__)
12
+
10
13
  # Load emoji data from config/emoji.txt and build the `text_to_emoji`
11
14
  # and `emoji_to_text` hash tables
12
15
  def self.initialize!
13
- emoji = File.read(File.expand_path('../../data/emoji.txt', __FILE__)).each_line.to_a
14
-
15
- @text_to_emoji = emoji.inject({}) do |memo, item|
16
- item = item.chomp.split("\t")
17
- memo.merge "{#{item[0]}}" => eval('"' + item[1] + '"')
18
- end
19
-
20
- @emoji_to_text = emoji.inject({}) do |memo, item|
21
- item = item.chomp.split("\t")
22
- memo.merge eval('"' + item[1] + '"') => "{#{item[0]}}"
23
- end
16
+ content = File.read(DATA_FILE).each_line.to_a
17
+ build_hash_tables(content)
24
18
  end
25
19
 
26
20
  # Loop through all emoji and replace them with
@@ -40,6 +34,23 @@ module Emojimmy
40
34
  @text_to_emoji[data]
41
35
  end
42
36
  end
37
+
38
+ private
39
+
40
+ # Build or `emoji_to_text` and `text_to_emoji` hash tables
41
+ def self.build_hash_tables(content)
42
+ @emoji_to_text = {}
43
+ @text_to_emoji = {}
44
+
45
+ content.each do |line|
46
+ line = line.chomp.split("\t")
47
+ emoji = eval('"' + line[1] + '"')
48
+ text = "{#{line[0]}}"
49
+
50
+ @emoji_to_text[emoji] = text
51
+ @text_to_emoji[text] = emoji
52
+ end
53
+ end
43
54
  end
44
55
 
45
56
  class ActiveRecord::Base
@@ -1,3 +1,3 @@
1
1
  module Emojimmy
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Emojimmy::Mixin do
@@ -16,13 +17,13 @@ describe Emojimmy::Mixin do
16
17
  subject { Comment.create(body: body) }
17
18
 
18
19
  context 'with a single emoji' do
19
- let(:body) { "Hello, \xF0\x9F\x98\x81 world!" }
20
+ let(:body) { "Hello, 😁😁 world!" }
20
21
  it { should be_persisted }
21
22
  its(:body) { should eql body }
22
23
  end
23
24
 
24
25
  context 'with multiple emoji' do
25
- let(:body) { "Hello, \xF0\x9F\x98\x81\xF0\x9F\x98\x81 \xF0\x9F\x98\x8D world!" }
26
+ let(:body) { "Hello, 😁😁😁 😍 world!" }
26
27
  it { should be_persisted }
27
28
  its(:body) { should eql body }
28
29
  end
@@ -39,13 +40,13 @@ describe Emojimmy::Mixin do
39
40
  let(:persisted_body) { subject.read_attribute(:body) }
40
41
 
41
42
  context 'with a single emoji' do
42
- let(:body) { "Hello, \xF0\x9F\x98\x81 world!" }
43
+ let(:body) { "Hello, 😁 world!" }
43
44
  it { should be_persisted }
44
45
  it { expect(persisted_body).to eql "Hello, {U+1F601} world!" }
45
46
  end
46
47
 
47
48
  context 'with multiple emoji' do
48
- let(:body) { "Hello, \xF0\x9F\x98\x81\xF0\x9F\x98\x81 \xF0\x9F\x98\x8D world!" }
49
+ let(:body) { "Hello, 😁😁 😍 world!" }
49
50
  it { should be_persisted }
50
51
  it { expect(persisted_body).to eql "Hello, {U+1F601}{U+1F601} {U+1F60D} world!" }
51
52
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Emojimmy do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emojimmy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - RΓ©mi PrΓ©vost