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 +4 -4
- data/lib/emojimmy.rb +22 -11
- data/lib/emojimmy/version.rb +1 -1
- data/spec/emojimmy/mixin_spec.rb +5 -4
- data/spec/emojimmy_spec.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 537d4a671f8d4f03de4905c27435d57b53d9b72b
|
4
|
+
data.tar.gz: 262e130bc35f71d5d0a33d38094a7b9aa3ed92ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/lib/emojimmy/version.rb
CHANGED
data/spec/emojimmy/mixin_spec.rb
CHANGED
@@ -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,
|
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,
|
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,
|
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,
|
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
|
data/spec/emojimmy_spec.rb
CHANGED