rumoji 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rack-emoji.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rumoji
2
2
 
3
- This is a tool to convert Emoji UTF-8 into the codes used by http://www.emoji-cheat-sheet.com/ and back again.
3
+ This is a tool to convert Emoji Unicode codepoints into the human-friendly codes used by http://www.emoji-cheat-sheet.com/ and back again.
4
4
 
5
5
  Why would you want to do this? Read this blog post: http://mwunsch.tumblr.com/post/34721548842/we-need-to-talk-about-emoji
6
6
 
@@ -46,9 +46,11 @@ On the command line
46
46
  echo "But Rumoji makes encoding issues a :joy:" | ruby ./funfile.rb
47
47
  #=> But Rumoji makes encoding issues a 😂
48
48
 
49
- Implement the emoji codes from emoji-cheat-sheet.com using a tool like [gemoji](https://github.com/github/gemoji) along with Rumoji, and you'll easily be able to transform user input with raw emoji utf-8 into images you can show to all users.
49
+ Implement the emoji codes from emoji-cheat-sheet.com using a tool like [gemoji](https://github.com/github/gemoji) along with Rumoji, and you'll easily be able to transform user input with raw emoji unicode into images you can show to all users.
50
50
 
51
- _Having trouble discerning what's happening in this README?_ You might be on a device with NO emoji support! All the more reason to use Rumoji. Transcode the raw utf-8 into something users can understand across devices!
51
+ Currently, Rumoji only supports the _People_ and _Nature_ characters in emoji-cheat-sheet, but that will change!
52
+
53
+ _Having trouble discerning what's happening in this README?_ You might be on a device with NO emoji support! All the more reason to use Rumoji. Transcode the raw unicode into something users can understand across devices!
52
54
 
53
55
  Thanks!
54
56
 
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "rake/testtask"
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs.push "lib"
6
- t.test_files = FileList['spec/*_spec.rb']
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
7
  t.verbose = true
8
8
  end
9
9
 
data/bin/rumoji ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ require 'rumoji'
5
+
6
+ Rumoji.decode_io(STDIN, STDOUT)
data/lib/rumoji.rb CHANGED
@@ -1,244 +1,39 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require "rumoji/version"
3
+ require "rumoji/emoji"
3
4
  require 'stringio'
4
5
 
5
6
  module Rumoji
6
7
  extend self
7
8
 
9
+ # Transform emoji into its cheat-sheet code
8
10
  def encode(str)
9
11
  remapped_codepoints = str.codepoints.flat_map do |codepoint|
10
- emoji = EMOJI_NAME_TO_CODEPOINT.key(codepoint.to_s(16).upcase)
11
- emoji ? ":#{emoji}:".codepoints.entries : codepoint
12
+ emoji = Emoji.find_by_codepoint(codepoint)
13
+ emoji ? emoji.code.codepoints.entries : codepoint
12
14
  end
13
15
  remapped_codepoints.pack("U*")
14
16
  end
15
17
 
18
+ # Transform a cheat-sheet code into an Emoji
16
19
  def decode(str)
17
- duplicate = str.dup
18
- EMOJI_NAME_TO_CODEPOINT.each_pair do |key, value|
19
- duplicate.gsub! ":#{key}:", [value.to_i(16)].pack("U")
20
- end
21
- duplicate
20
+ str.gsub(/:(\S?\w+):/) {|sym| Emoji.find($1.intern).to_s }
22
21
  end
23
22
 
24
23
  def encode_io(readable, writeable=StringIO.new(""))
25
24
  readable.each_codepoint do |codepoint|
26
- emoji = codepoint.to_s(16).upcase
27
- emoji_or_character = EMOJI_NAME_TO_CODEPOINT.has_value?(emoji) ? ":#{EMOJI_NAME_TO_CODEPOINT.key(emoji)}:" : [codepoint].pack("U")
25
+ emoji = Emoji.find_by_codepoint(codepoint)
26
+ emoji_or_character = emoji ? emoji.code : [codepoint].pack("U")
28
27
  writeable.write emoji_or_character
29
28
  end
30
- writeable.rewind
31
29
  writeable
32
30
  end
33
31
 
34
32
  def decode_io(readable, writeable=StringIO.new(""))
35
- readable.each do |word|
36
- EMOJI_NAME_TO_CODEPOINT.each_pair do |key,value|
37
- word.gsub!(":#{key}:", [value.to_i(16)].pack("U"))
38
- end
39
- writeable.write(word)
33
+ readable.each_line do |line|
34
+ writeable.write decode(line)
40
35
  end
41
- writeable.rewind
42
36
  writeable
43
37
  end
44
38
 
45
- EMOJI_NAME_TO_CODEPOINT = {
46
- # PEOPLE
47
- smile: "1F604",
48
- laughing: "1F606",
49
- blush: "1F60A",
50
- smiley: "1F603",
51
- relaxed: "263A",
52
- smirk: "1F60F",
53
- heart_eyes: "1F60D",
54
- kissing_heart: "1F618",
55
- kissing_closed_eyes: "1F61A",
56
- flushed: "1F633",
57
- relieved: "1F625",
58
- satisfied: "1F60C",
59
- grin: "1F601",
60
- wink: "1F609",
61
- wink2: "1F61C",
62
- stuck_out_tongue_winking_eye: "1F61C",
63
- stuck_out_tongue_closed_eyes: "1F61D",
64
- grinning: "1F600",
65
- kissing: "1F617",
66
- kissing_smiling_eyes: "1F619",
67
- stuck_out_tongue: "1F61B",
68
- sleeping: "1F634",
69
- worried: "1F61F",
70
- frowning: "1F626",
71
- anguished: "1F627",
72
- open_mouth: "1F62E",
73
- grimacing: "1F62C",
74
- confused: "1F615",
75
- hushed: "1F62F",
76
- expressionless: "1F611",
77
- unamused: "1F612",
78
- sweat_smile: "1F605",
79
- sweat: "1F613",
80
- weary: "1F629",
81
- pensive: "1F614",
82
- dissapointed: "1F61E",
83
- confounded: "1F616",
84
- fearful: "1F628",
85
- cold_sweat: "1F630",
86
- persevere: "1F623",
87
- cry: "1F622",
88
- sob: "1F62D",
89
- joy: "1F602",
90
- astonished: "1F632",
91
- scream: "1F631",
92
- tired_face: "1F62B",
93
- angry: "1F620",
94
- rage: "1F621",
95
- triumph: "1F624",
96
- sleepy: "1F62A",
97
- yum: "1F60B",
98
- mask: "1F637",
99
- sunglasses: "1F60E",
100
- dizzy_face: "1F635",
101
- imp: "1F47F",
102
- smiling_imp: "1F608",
103
- neutral_face: "1F610",
104
- no_mouth: "1F636",
105
- innocent: "1F607",
106
-
107
- alien: "1F47D",
108
-
109
- yellow_heart: "1F49B",
110
- blue_heart: "1F499",
111
- purple_heart: "1F49C",
112
- heart: "2764",
113
- green_heart: "1F49A",
114
- broken_heart: "1F494",
115
- heartbeat: "1F493",
116
- heartpulse: "1F497",
117
- two_hearts: "1F495",
118
- revolving_hearts: "1F49E",
119
- cupid: "1F498",
120
- sparkling_heart: "1F496",
121
-
122
- sparkles: "2728",
123
- star: "2B50", # In "Nature" range
124
- star2: "1F31F",
125
- dizzy: "1F4AB",
126
- boom: "1F4A5",
127
- collision: "1F4A5",
128
- anger: "1F4A2",
129
-
130
- # In "Symbols" range
131
- exclamation: "2757",
132
- question: "2753",
133
- grey_exclamation: "2755",
134
- grey_question: "2754",
135
-
136
- zzz: "1F4A4",
137
- dash: "1F4A8",
138
- sweat_drops: "1F4A6",
139
-
140
- # In "Objects" range
141
- notes: "1F3B6",
142
- musical_note: "1F3B5",
143
-
144
- fire: "1F525",
145
-
146
- # So much poop
147
- hankey: "1F4A9",
148
- poop: "1F4A9",
149
- shit: "1F4A9",
150
-
151
- thumbsup: "1F44D",
152
- thumbsdown: "1F44E",
153
- ok_hand: "1F44C",
154
- punch: "1F44A",
155
- facepunch: "1F44A",
156
- fist: "270A",
157
- v: "270C",
158
- wave: "1F44B",
159
- hand: "270B",
160
-
161
- open_hands: "1F450",
162
- point_up: "261D",
163
- point_down: "1F447",
164
- point_left: "1F448",
165
- point_right: "1F449",
166
- raised_hands: "1F64C",
167
- pray: "1F64F",
168
- point_up_2: "1F446",
169
- clap: "1F44F",
170
- muscle: "1F4AA",
171
-
172
- walking: "1F6B6",
173
- runner: "1F3C3",
174
- running: "1F3C3",
175
- couple: "1F46B",
176
- family: "1F46A",
177
- two_men_holding_hands: "1F46C",
178
- two_women_holding_hands: "1F46C",
179
- dancer: "1F483",
180
- dancers: "1F46F",
181
- ok_woman: "1F646",
182
- no_good: "1F645",
183
- information_desk_person: "1F481",
184
- raised_hand: "1F64B",
185
- bride_with_veil: "1F470",
186
- person_with_pouting_face: "1F64E",
187
- person_frowning: "1F64D",
188
- bow: "1F647",
189
- couplekiss: "1F48F",
190
- couple_with_heart: "1F491",
191
- massage: "1F486",
192
- haircut: "1F487",
193
- nail_care: "1F485",
194
- boy: "1F466",
195
- girl: "1F467",
196
- woman: "1F469",
197
- man: "1F468",
198
- baby: "1F476",
199
- older_woman: "1F475",
200
- older_man: "1F474",
201
- person_with_blond_hair: "1F471",
202
- man_with_gua_pi_mao: "1F472",
203
- man_with_turban: "1F473",
204
- construction_worker: "1F477",
205
- cop: "1F46E",
206
- angel: "1F47C",
207
- princess: "1F478",
208
-
209
- smiley_cat: "1F63A",
210
- smile_cat: "1F638",
211
- heart_eyes_cat: "1F63B",
212
- kissing_cat: "1F63D",
213
- smirk_cat: "1F63C",
214
- scream_cat: "1F640",
215
- crying_cat_face: "1F63F",
216
- joy_cat: "1F639",
217
- pouting_cat: "1F63E",
218
-
219
- japanese_ogre: "1F479",
220
- japanese_goblin: "1F47A",
221
-
222
- see_no_evil: "1F648",
223
- hear_no_evil: "1F649",
224
- speak_no_evil: "1F649",
225
-
226
- guardsman: "1F482",
227
- skull: "1F480",
228
-
229
- feet: "1F463",
230
- lips: "1F444",
231
- kiss: "1F48B",
232
- droplet: "1F4A7",
233
- ear: "1F442",
234
- eyes: "1F440",
235
- nose: "1F443",
236
- tongue: "1F445",
237
- love_letter: "1F48C",
238
- bust_in_silhouette: "1F464",
239
- busts_in_silhouette: "1F465",
240
- speech_balloon: "1F4AC",
241
- thought_balloon: "1F4AD"
242
- }
243
-
244
39
  end
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Rumoji
3
+ class Emoji
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(string, symbols, name = nil)
8
+ @codepoints = string.codepoints
9
+ @cheat_codes = [symbols].flatten
10
+ @name = name || @cheat_codes.first.to_s.upcase.gsub("_", " ")
11
+ end
12
+
13
+ def symbol
14
+ @cheat_codes.first
15
+ end
16
+
17
+ def code
18
+ ":#{symbol}:"
19
+ end
20
+
21
+ def include?(symbol)
22
+ @cheat_codes.include? symbol.to_sym
23
+ end
24
+
25
+ def to_s
26
+ @codepoints.to_a.pack("U*")
27
+ end
28
+
29
+ def hash
30
+ code.hash
31
+ end
32
+
33
+ def hex
34
+ @codepoints.map{|point| point.to_s(16).upcase }.join("-")
35
+ end
36
+
37
+ autoload :PEOPLE, 'rumoji/emoji/people'
38
+ autoload :NATURE, 'rumoji/emoji/nature'
39
+ autoload :OBJECTS, 'rumoji/emoji/objects'
40
+ autoload :PLACES, 'rumoji/emoji/places'
41
+ autoload :SYMBOLS, 'rumoji/emoji/symbols'
42
+
43
+ ALL = PEOPLE | NATURE | OBJECTS | PLACES | SYMBOLS
44
+
45
+ def self.find(symbol)
46
+ ALL.find {|emoji| emoji.include? symbol }
47
+ end
48
+
49
+ def self.find_by_string(string)
50
+ ALL.find {|emoji| emoji.to_s == string }
51
+ end
52
+
53
+ def self.find_by_codepoint(codepoint)
54
+ ALL.find {|emoji| emoji.hex == codepoint.to_s(16).upcase }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,127 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rumoji/emoji'
4
+ require 'set'
5
+
6
+ module Rumoji
7
+ class Emoji
8
+ NATURE = Set[
9
+ self.new("\u{2600}" , [:sunny], "BLACK SUN WITH RAYS"),
10
+ self.new("\u{2614}" , [:umbrella], "UMBRELLA WITH RAIN DROPS"),
11
+ self.new("\u{2601}" , [:cloud]),
12
+ self.new("\u{2744}" , [:snowflake]),
13
+ self.new("\u{26C4}" , [:snowman], "SNOWMAN WITHOUT SNOW"),
14
+ self.new("\u{26A1}" , [:zap], "HIGH VOLTAGE SIGN"),
15
+ self.new("\u{1F300}", [:cyclone]), # "typhoon, hurricane
16
+ self.new("\u{1F301}", [:foggy]),
17
+ self.new("\u{1F30A}", [:ocean], "WATER WAVE"),
18
+ # Animals
19
+ self.new("\u{1F431}", [:cat], "CAT FACE"),
20
+ self.new("\u{1F436}", [:dog], "DOG FACE"),
21
+ self.new("\u{1F42D}", [:mouse], "MOUSE FACE"),
22
+ self.new("\u{1F439}", [:hamster], "HAMSTER FACE"),
23
+ self.new("\u{1F430}", [:rabbit], "RABBIT FACE"),
24
+ self.new("\u{1F43A}", [:wolf], "WOLF FACE"),
25
+ self.new("\u{1F438}", [:frog], "FROG FACE"),
26
+ self.new("\u{1F42F}", [:tiger], "TIGER FACE"),
27
+ self.new("\u{1F428}", [:koala]),
28
+ self.new("\u{1F43B}", [:bear], "BEAR FACE"),
29
+ self.new("\u{1F437}", [:pig], "PIG FACE"),
30
+ self.new("\u{1F43D}", [:pig_nose]),
31
+ self.new("\u{1F42E}", [:cow], "COW FACE"),
32
+ self.new("\u{1F417}", [:boar]),
33
+ self.new("\u{1F435}", [:monkey_face]),
34
+ self.new("\u{1F412}", [:monkey]),
35
+ self.new("\u{1F434}", [:horse], "HORSE FACE"),
36
+ self.new("\u{1F40E}", [:racehorse], "HORSE"),
37
+ self.new("\u{1F42B}", [:camel], "BACTRIAN CAMEL"), # "has two humps"
38
+ self.new("\u{1F411}", [:sheep]),
39
+ self.new("\u{1F418}", [:elephant]),
40
+ self.new("\u{1F43C}", [:panda_face]),
41
+ self.new("\u{1F40D}", [:snake]),
42
+ self.new("\u{1F426}", [:bird]),
43
+ self.new("\u{1F424}", [:baby_chick]),
44
+ self.new("\u{1F425}", [:hatched_chick], "FRONT-FACING BABY CHICK"),
45
+ self.new("\u{1F423}", [:hatching_chick]),
46
+ self.new("\u{1F414}", [:chicken]),
47
+ self.new("\u{1F427}", [:penguin]),
48
+ self.new("\u{1F422}", [:turtle]),
49
+ self.new("\u{1F41B}", [:bug]),
50
+ self.new("\u{1F41D}", [:honeybee]),
51
+ self.new("\u{1F41C}", [:ant]),
52
+ self.new("\u{1F41E}", [:beetle], "LADY BEETLE"), # "ladybird, ladybug, coccinellids"
53
+ self.new("\u{1F40C}", [:snail]),
54
+ self.new("\u{1F419}", [:octopus]),
55
+ self.new("\u{1F420}", [:tropical_fish]),
56
+ self.new("\u{1F41F}", [:fish]),
57
+ self.new("\u{1F433}", [:whale], "SPOUTING WHALE"),
58
+ self.new("\u{1F40B}", [:whale2], "WHALE"),
59
+ self.new("\u{1F42C}", [:dolphin]),
60
+ self.new("\u{1F404}", [:cow2], "COW"),
61
+ self.new("\u{1F40F}", [:ram]),
62
+ self.new("\u{1F400}", [:rat]),
63
+ self.new("\u{1F403}", [:water_buffalo]),
64
+ self.new("\u{1F405}", [:tiger2], "TIGER"),
65
+ self.new("\u{1F407}", [:rabbit2], "RABBIT"),
66
+ self.new("\u{1F409}", [:dragon]),
67
+ self.new("\u{1F410}", [:goat]),
68
+ self.new("\u{1F413}", [:rooster]),
69
+ self.new("\u{1F415}", [:dog2], "DOG"),
70
+ self.new("\u{1F416}", [:pig2], "PIG"),
71
+ self.new("\u{1F401}", [:mouse2], "MOUSE"),
72
+ self.new("\u{1F402}", [:ox]),
73
+ self.new("\u{1F432}", [:dragon_face]),
74
+ self.new("\u{1F421}", [:blowfish]),
75
+ self.new("\u{1F40A}", [:crocodile]),
76
+ self.new("\u{1F42A}", [:dromedary_camel]), # "has a single hump"
77
+ self.new("\u{1F406}", [:leopard]),
78
+ self.new("\u{1F408}", [:cat2], "CAT"),
79
+ self.new("\u{1F429}", [:poodle]),
80
+ self.new("\u{1F43E}", [:paw_prints]),
81
+ # Flowers
82
+ self.new("\u{1F490}", [:bouquet]),
83
+ self.new("\u{1F338}", [:cherry_blossom]),
84
+ self.new("\u{1F337}", [:tulip]),
85
+ self.new("\u{1F340}", [:four_leaf_clover]),
86
+ self.new("\u{1F339}", [:rose]),
87
+ self.new("\u{1F33B}", [:sunflower]),
88
+ self.new("\u{1F33A}", [:hibiscus]),
89
+ self.new("\u{1F341}", [:maple_leaf]),
90
+ self.new("\u{1F343}", [:leaves], "LEAF FLUTTERING IN WIND"),
91
+ self.new("\u{1F342}", [:fallen_leaf]),
92
+ self.new("\u{1F33F}", [:herb]),
93
+ self.new("\u{1F344}", [:mushroom]),
94
+ self.new("\u{1F335}", [:cactus]),
95
+ self.new("\u{1F334}", [:palm_tree]),
96
+ self.new("\u{1F332}", [:evergreen_tree]),
97
+ self.new("\u{1F333}", [:deciduous_tree]),
98
+ self.new("\u{1F330}", [:chestnut]),
99
+ self.new("\u{1F331}", [:seedling]),
100
+ self.new("\u{1F33C}", [:blossum]), # "daisy"
101
+ self.new("\u{1F33E}", [:ear_of_rice]),
102
+ self.new("\u{1F41A}", [:shell], "SPIRAL SHELL"),
103
+ self.new("\u{1F310}", [:globe_with_meridians]), # "used to indicate international input source, world clocks with time zones, etc."
104
+ # Moon
105
+ self.new("\u{1F31E}", [:sun_with_face]),
106
+ self.new("\u{1F31D}", [:full_moon_with_face]),
107
+ self.new("\u{1F31A}", [:new_moon_with_face]),
108
+ self.new("\u{1F311}", [:new_moon], "NEW MOON SYMBOL"),
109
+ self.new("\u{1F312}", [:waxing_crescent_moon], "WAXING CRESCENT MOON SYMBOL"),
110
+ self.new("\u{1F313}", [:first_quarter_moon], "FIRST QUARTER MOON SYMBOL"), # "half moon"
111
+ self.new("\u{1F314}", [:waxing_gibbous_moon], "WAXING GIBBOUS MOON SYMBOL"), # "waxing moon"
112
+ self.new("\u{1F315}", [:full_moon], "FULL MOON SYMBOL"),
113
+ self.new("\u{1F316}", [:waning_gibbous_moon], "WAINING GIBBOUS MOON SYMBOL"),
114
+ self.new("\u{1F317}", [:last_quarter_moon], "LAST QUARTER MOON SYMBOL"),
115
+ self.new("\u{1F318}", [:waning_crescent_moon], "WANING CRESCENT MOON SYMBOL"),
116
+ self.new("\u{1F31C}", [:last_quarter_moon_with_face]),
117
+ self.new("\u{1F31B}", [:first_quarter_moon_with_face]),
118
+ self.new("\u{1F319}", [:moon], "CRESCENT MOON"), # "may indicate either the first or last quarter moon"
119
+ self.new("\u{1F30D}", [:earth_africa], "EARTH GLOBE EUROPE-AFRICA"),
120
+ self.new("\u{1F30E}", [:earth_americas], "EARTH GLOBE AMERICAS"),
121
+ self.new("\u{1F30F}", [:earth_asia], "EARTH GLOBE ASIA-AUSTRALIA"),
122
+ self.new("\u{1F30B}", [:volcano]),
123
+ self.new("\u{1F30C}", [:milky_way]),
124
+ self.new("\u{26C5}" , [:partly_sunny], "SUN BEHIND CLOUD")
125
+ ]
126
+ end
127
+ end