emoji_sub 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module EmojiSub
5
5
  EMOJI_MAPPING_YAML = "data/emoji.yaml"
6
6
 
7
7
  def emoji_sub(text, additional_mappings = {})
8
- known_emoji = YAML.load(File.read(EMOJI_MAPPING_YAML)).merge(additional_mappings)
8
+ known_emoji = emoji_definitions.merge(additional_mappings)
9
9
 
10
10
  discovered_emoji = text.scan(/:([\w\d\-\_]+):/).flatten.map(&:to_sym).uniq
11
11
  found = discovered_emoji.each_with_object({}) do |emoji, found|
@@ -13,12 +13,18 @@ module EmojiSub
13
13
  end.compact
14
14
 
15
15
  found.each do |shortcode, unicode|
16
- text.gsub!(/:#{shortcode}:/, "&#x#{unicode}")
16
+ text.gsub!(/:#{shortcode}:/, Array(unicode).map { |u| "&#x#{u}" }.join(''))
17
17
  end
18
18
 
19
19
  text
20
20
  end
21
- module_function :emoji_sub
22
21
 
22
+ def emoji_definitions
23
+ m = YAML.load(File.read(EMOJI_MAPPING_YAML)).values
24
+ @emoji_definitions ||= m.inject({}) { |a,memo| memo.merge(a) }
25
+
26
+ #@emoji_definitions ||= m.collect(&:values).flatten
27
+ end
28
+ module_function :emoji_sub, :emoji_definitions
23
29
 
24
30
  end
@@ -1,3 +1,3 @@
1
1
  module EmojiSub
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emoji_sub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Hill
@@ -33,7 +33,6 @@ files:
33
33
  - data/emoji.yaml
34
34
  - emoji_sub.gemspec
35
35
  - lib/emoji_sub.rb
36
- - lib/emoji_sub/emoji_parser.rb
37
36
  - lib/emoji_sub/version.rb
38
37
  homepage: https://github.com/armahillo/emoji_sub
39
38
  licenses:
@@ -1,25 +0,0 @@
1
- require 'YAML'
2
-
3
- def emoji_sub(text)
4
- known_emoji = load_emoji
5
- discovered_emoji = text.scan(/:([\w\d\-\_]+):/).flatten.map(&:to_sym).uniq
6
- found = discovered_emoji.each_with_object({}) do |emoji, found|
7
- found[emoji] = known_emoji.fetch(emoji,'')
8
- end
9
-
10
- found.each do |shortcode, unicode|
11
- text.gsub!(/:#{shortcode}:/, "&#x#{unicode}")
12
- end
13
-
14
- text
15
- end
16
-
17
- def load_emoji
18
- YAML.load(File.read('emoji.yaml'))
19
- end
20
-
21
-
22
-
23
- TEXT = 'This is testing text :100: :100: :100: :bad_dude: It is great :slightly_smiling_face:.'
24
-
25
- p emoji_sub(TEXT)