rumoji 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-emoji.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mark Wunsch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Rumoji
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.
4
+
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
+
7
+ ## tl;dr
8
+
9
+ >**Do not store emoji unicodes in your database. Store the human-friendly code and support the emoji-cheat-sheet.**
10
+
11
+ >By doing this, you can ensure that users across devices can see the author’s intention. You can always show users an image, but you can’t show them a range of characters their system does not support.
12
+
13
+ ## Usage
14
+
15
+ Rumoji.encode(str)
16
+ # Takes a String, transforms Emoji into cheat-sheet codes
17
+
18
+ Rumoji.decode(str)
19
+ # Does the reverse
20
+
21
+ Rumoji.encode_io(read, write)
22
+ # For an IO pipe (a read stream, and a write stream), transform Emoji from the
23
+ # read end, and write the cheat-sheet codes on the write end.
24
+
25
+ Rumoji.decode_io(read, write)
26
+ # Same thing but in reverse!
27
+
28
+ ## Installation
29
+
30
+ gem install rumoji
31
+
32
+ Note that rumoji has only been tested in Ruby 1.9!!!
33
+
34
+ ### Some examples:
35
+
36
+ puts Rumoji.encode("Lack of cross-device emoji support makes me 😭")
37
+
38
+ #=> Lack of cross-device emoji support makes me :sob:
39
+
40
+ Here's a fun file:
41
+
42
+ Rumoji.decode_io($stdin, $stdout)
43
+
44
+ On the command line
45
+
46
+ echo "But Rumoji makes encoding issues a :joy:" | ruby ./funfile.rb
47
+ #=> But Rumoji makes encoding issues a 😂
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.
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!
52
+
53
+ Thanks!
54
+
55
+ ## Copyright
56
+ Copyright (c) 2009 - 2012 Mark Wunsch. Licensed under the [MIT License](http://opensource.org/licenses/mit-license.php).
57
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => [:test]
@@ -0,0 +1,244 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "rumoji/version"
3
+ require 'stringio'
4
+
5
+ module Rumoji
6
+ extend self
7
+
8
+ def encode(str)
9
+ 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
+ end
13
+ remapped_codepoints.pack("U*")
14
+ end
15
+
16
+ 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
22
+ end
23
+
24
+ def encode_io(readable, writeable=StringIO.new(""))
25
+ 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")
28
+ writeable.write emoji_or_character
29
+ end
30
+ writeable.rewind
31
+ writeable
32
+ end
33
+
34
+ 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)
40
+ end
41
+ writeable.rewind
42
+ writeable
43
+ end
44
+
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
+ end
@@ -0,0 +1,3 @@
1
+ module Rumoji
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rumoji/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rumoji"
8
+ gem.version = Rumoji::VERSION
9
+ gem.authors = ["Mark Wunsch"]
10
+ gem.email = ["mark@markwunsch.com"]
11
+ gem.description = %q{Transcode emoji utf-8 characters into emoji-cheat-sheet form}
12
+ gem.summary = %q{Transcode emoji utf-8 characters into emoji-cheat-sheet form}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rumoji'
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+
6
+ describe Rumoji do
7
+ before do
8
+ @poop = "💩"
9
+ @smile = "😄"
10
+ end
11
+
12
+ describe "#encode" do
13
+ it "transforms emoji into cheat-sheet form" do
14
+ key = :smile
15
+ Rumoji.encode(@smile).must_equal ":smile:"
16
+ end
17
+ end
18
+
19
+ describe "#decode" do
20
+ it "transforms a cheat-sheet code into an emoji" do
21
+ Rumoji.decode(":poop:").must_equal @poop
22
+ end
23
+ end
24
+
25
+ describe "#encode_io" do
26
+ it "reads emoji from one stream and outputs a stream of cheat-sheet codes" do
27
+ io = StringIO.new("#{@smile}")
28
+ Rumoji.encode_io(io).read.must_equal ":smile:"
29
+ end
30
+ end
31
+
32
+ describe "#decode_io" do
33
+ it "reads a cheat-sheet code from one stream and outputs a stream of emoji" do
34
+ io = StringIO.new(":poop:")
35
+ Rumoji.decode_io(io).read.must_equal @poop
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumoji
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Wunsch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-31 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Transcode emoji utf-8 characters into emoji-cheat-sheet form
15
+ email:
16
+ - mark@markwunsch.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/rumoji.rb
27
+ - lib/rumoji/version.rb
28
+ - rumoji.gemspec
29
+ - spec/rumoji_spec.rb
30
+ homepage: ''
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ segments:
43
+ - 0
44
+ hash: 2529029853417925007
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ segments:
52
+ - 0
53
+ hash: 2529029853417925007
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.23
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Transcode emoji utf-8 characters into emoji-cheat-sheet form
60
+ test_files:
61
+ - spec/rumoji_spec.rb