rumoji 0.2.0 β†’ 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf0ea637726fd3740573925b2493779578d668f2
4
+ data.tar.gz: 4a7f853c96be89f634dc595f9066baf6e235ab27
5
+ SHA512:
6
+ metadata.gz: 5cd83e867da5fb3dfb5a0e7b236836a5b725459fa9680f22848d2b370b9f96f2228f21f0c303830d967538e1f9fffde3be6102c2044e2dc1448c0f2e555d96d8
7
+ data.tar.gz: 103e290099c4e868be870a007e4103a7a8cbcb5856b22c9d903f1370d84bb2c6e857d98ed9acf6349068f5996175eea6dee305d01707689c8bcc1c98492b1766
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - rbx-19mode
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Mark Wunsch
1
+ Copyright (c) 2013 Mark Wunsch
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
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.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -48,12 +48,10 @@ On the command line
48
48
 
49
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
- Currently, Rumoji only supports the _People_ and _Nature_ characters in emoji-cheat-sheet, but that will change!
52
-
53
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 unicode into something users can understand across devices!
54
52
 
55
53
  Thanks!
56
54
 
57
55
  ## Copyright
58
- Copyright (c) 2009 - 2012 Mark Wunsch. Licensed under the [MIT License](http://opensource.org/licenses/mit-license.php).
56
+ Copyright (c) 2012 - 2013 Mark Wunsch. Licensed under the [MIT License](http://opensource.org/licenses/mit-license.php).
59
57
 
@@ -8,11 +8,8 @@ module Rumoji
8
8
 
9
9
  # Transform emoji into its cheat-sheet code
10
10
  def encode(str)
11
- remapped_codepoints = str.codepoints.flat_map do |codepoint|
12
- emoji = Emoji.find_by_codepoint(codepoint)
13
- emoji ? emoji.code.codepoints.entries : codepoint
14
- end
15
- remapped_codepoints.pack("U*")
11
+ io = StringIO.new(str)
12
+ encode_io(io).string
16
13
  end
17
14
 
18
15
  # Transform a cheat-sheet code into an Emoji
@@ -21,12 +18,30 @@ module Rumoji
21
18
  end
22
19
 
23
20
  def encode_io(readable, writeable=StringIO.new(""))
24
- readable.each_codepoint do |codepoint|
25
- emoji = Emoji.find_by_codepoint(codepoint)
26
- emoji_or_character = emoji ? emoji.code : [codepoint].pack("U")
27
- writeable.write emoji_or_character
21
+ codepoints = readable.each_codepoint
22
+ previous_emoji = []
23
+
24
+ codepoints.each_with_object(writeable) do |codepoint, writer|
25
+ possible_emoji = Emoji.select_by_codepoint(codepoint)
26
+ last_emoji = previous_emoji.pop
27
+
28
+ sequence = if last_emoji.nil? || !last_emoji.codepoints.include?(codepoint)
29
+ if possible_emoji.empty?
30
+ [codepoint].pack("U")
31
+ else
32
+ multiple_codepoint_emoji = possible_emoji.select(&:multiple?)
33
+ if multiple_codepoint_emoji.empty?
34
+ possible_emoji.first.code
35
+ else
36
+ previous_emoji.concat(multiple_codepoint_emoji) ; ""
37
+ end
38
+ end
39
+ else
40
+ last_emoji.code
41
+ end
42
+
43
+ writer.write sequence
28
44
  end
29
- writeable
30
45
  end
31
46
 
32
47
  def decode_io(readable, writeable=StringIO.new(""))
@@ -36,4 +51,7 @@ module Rumoji
36
51
  writeable
37
52
  end
38
53
 
54
+ private
55
+
56
+
39
57
  end
@@ -23,7 +23,7 @@ module Rumoji
23
23
  end
24
24
 
25
25
  def to_s
26
- @codepoints.to_a.pack("U*")
26
+ codepoints.pack("U*")
27
27
  end
28
28
 
29
29
  def hash
@@ -34,6 +34,14 @@ module Rumoji
34
34
  @codepoints.map{|point| point.to_s(16).upcase }.join("-")
35
35
  end
36
36
 
37
+ def codepoints
38
+ @codepoints.entries
39
+ end
40
+
41
+ def multiple?
42
+ codepoints.size > 1
43
+ end
44
+
37
45
  autoload :PEOPLE, 'rumoji/emoji/people'
38
46
  autoload :NATURE, 'rumoji/emoji/nature'
39
47
  autoload :OBJECTS, 'rumoji/emoji/objects'
@@ -50,6 +58,10 @@ module Rumoji
50
58
  ALL.find {|emoji| emoji.to_s == string }
51
59
  end
52
60
 
61
+ def self.select_by_codepoint(codepoint)
62
+ ALL.select {|emoji| emoji.codepoints.first.eql? codepoint }
63
+ end
64
+
53
65
  def self.find_by_codepoint(codepoint)
54
66
  ALL.find {|emoji| emoji.hex == codepoint.to_s(16).upcase }
55
67
  end
@@ -97,7 +97,7 @@ module Rumoji
97
97
  self.new("\u{1F333}", [:deciduous_tree]),
98
98
  self.new("\u{1F330}", [:chestnut]),
99
99
  self.new("\u{1F331}", [:seedling]),
100
- self.new("\u{1F33C}", [:blossum]), # "daisy"
100
+ self.new("\u{1F33C}", [:blossom]), # "daisy"
101
101
  self.new("\u{1F33E}", [:ear_of_rice]),
102
102
  self.new("\u{1F41A}", [:shell], "SPIRAL SHELL"),
103
103
  self.new("\u{1F310}", [:globe_with_meridians]), # "used to indicate international input source, world clocks with time zones, etc."
@@ -20,7 +20,7 @@ module Rumoji
20
20
  self.new("\u{1F60C}", [:satisfied], "RELIEVED FACE"),
21
21
  self.new("\u{1F601}", [:grin], "GRINNING FACE WITH SMILING EYES"),
22
22
  self.new("\u{1F609}", [:wink], "WINKING FACE"),
23
- self.new("\u{1F61C}", [:wink2, :stuck_out_tongue_winking_eye], "FACE WITH STUCK OUT TONGUE AND WINKING EYE"), # "kidding, not serious"
23
+ self.new("\u{1F61C}", [:stuck_out_tongue_winking_eye, :wink2], "FACE WITH STUCK OUT TONGUE AND WINKING EYE"), # "kidding, not serious"
24
24
  self.new("\u{1F61D}", [:stuck_out_tongue_closed_eyes], "FACE WITH STUCK-OUT TONGUE AND TIGHTLY-CLOSED EYES"), # "kidding, not serious"
25
25
  self.new("\u{1F600}", [:grinning], "GRINNING FACE"),
26
26
  self.new("\u{1F617}", [:kissing], "KISSING FACE"),
@@ -40,7 +40,7 @@ module Rumoji
40
40
  self.new("\u{1F613}", [:sweat], "FACE WITH COLD SWEAT"),
41
41
  self.new("\u{1F629}", [:weary], "WEARY FACE"),
42
42
  self.new("\u{1F614}", [:pensive], "PENSIVE FACE"),
43
- self.new("\u{1F61E}", [:dissapointed], "DISAPPOINTED FACE"),
43
+ self.new("\u{1F61E}", [:disappointed], "DISAPPOINTED FACE"),
44
44
  self.new("\u{1F616}", [:confounded], "CONFOUNDED FACE"),
45
45
  self.new("\u{1F628}", [:fearful], "FEARFUL FACE"),
46
46
  self.new("\u{1F630}", [:cold_sweat], "FACE WITH OPEN MOUTH AND COLD SWEAT"),
@@ -98,16 +98,16 @@ module Rumoji
98
98
  self.new("\u{26a0}" , [:warning]),
99
99
  self.new("\u{1f492}", [:wedding]),
100
100
  # Regional Indicator Symbols
101
- self.new("\u{1f1ef}\u{1f1f5}", [:jp], "REGIONAL INDICATOR SYMBOL LETTERS JP"),
102
- self.new("\u{1f1f0}\u{1f1f7}", [:kr], "REGIONAL INDICATOR SYMBOL LETTERS KR"),
103
- self.new("\u{1f1e8}\u{1f1f3}", [:cn], "REGIONAL INDICATOR SYMBOL LETTERS CN"),
104
- self.new("\u{1f1fa}\u{1f1f8}", [:us], "REGIONAL INDICATOR SYMBOL LETTERS US"),
105
- self.new("\u{1f1eb}\u{1f1f7}", [:fr], "REGIONAL INDICATOR SYMBOL LETTERS FR"),
106
- self.new("\u{1f1ea}\u{1f1f8}", [:es], "REGIONAL INDICATOR SYMBOL LETTERS ES"),
107
- self.new("\u{1f1ee}\u{1f1f9}", [:it], "REGIONAL INDICATOR SYMBOL LETTERS IT"),
108
- self.new("\u{1f1f7}\u{1f1fa}", [:ru], "REGIONAL INDICATOR SYMBOL LETTERS RU"),
109
- self.new("\u{1f1ec}\u{1f1e7}", [:gb, :uk], "REGIONAL INDICATOR SYMBOL LETTERS GB"),
110
- self.new("\u{1f1e9}\u{1f1ea}", [:de], "REGIONAL INDICATOR SYMBOL LETTERS DE"),
101
+ self.new("\u{1f1ef 1f1f5}", [:jp], "REGIONAL INDICATOR SYMBOL LETTERS JP"),
102
+ self.new("\u{1f1f0 1f1f7}", [:kr], "REGIONAL INDICATOR SYMBOL LETTERS KR"),
103
+ self.new("\u{1f1e8 1f1f3}", [:cn], "REGIONAL INDICATOR SYMBOL LETTERS CN"),
104
+ self.new("\u{1f1fa 1f1f8}", [:us], "REGIONAL INDICATOR SYMBOL LETTERS US"),
105
+ self.new("\u{1f1eb 1f1f7}", [:fr], "REGIONAL INDICATOR SYMBOL LETTERS FR"),
106
+ self.new("\u{1f1ea 1f1f8}", [:es], "REGIONAL INDICATOR SYMBOL LETTERS ES"),
107
+ self.new("\u{1f1ee 1f1f9}", [:it], "REGIONAL INDICATOR SYMBOL LETTERS IT"),
108
+ self.new("\u{1f1f7 1f1fa}", [:ru], "REGIONAL INDICATOR SYMBOL LETTERS RU"),
109
+ self.new("\u{1f1ec 1f1e7}", [:gb, :uk], "REGIONAL INDICATOR SYMBOL LETTERS GB"),
110
+ self.new("\u{1f1e9 1f1ea}", [:de], "REGIONAL INDICATOR SYMBOL LETTERS DE"),
111
111
  ]
112
112
  end
113
113
  end
@@ -81,16 +81,16 @@ module Rumoji
81
81
  self.new("\u{1f6c3}", [:customs]),
82
82
  self.new("\u{1f4a0}", [:diamond_shape_with_a_dot_inside]),
83
83
  self.new("\u{1f6af}", [:do_not_litter]),
84
- self.new("\u{0038}" , [:eight]),
84
+ self.new("\u{0038 20e3}" , [:eight]),
85
85
  self.new("\u{2734}" , [:eight_pointed_black_star]),
86
86
  self.new("\u{2733}" , [:eight_spoked_asterisk]),
87
87
  self.new("\u{1f51a}", [:end]),
88
88
  self.new("\u{23e9}" , [:fast_forward]),
89
- self.new("\u{0035}" , [:five]),
90
- self.new("\u{0034}" , [:four]),
89
+ self.new("\u{0035 20e3}" , [:five]),
90
+ self.new("\u{0034 20e3}" , [:four]),
91
91
  self.new("\u{1f193}", [:free]),
92
92
  self.new("\u{264a}" , [:gemini]),
93
- self.new("\u{0023}" , [:hash]),
93
+ self.new("\u{0023 20e3}" , [:hash]),
94
94
  self.new("\u{1f49f}", [:heart_decoration]),
95
95
  self.new("\u{2714}" , [:heavy_check_mark]),
96
96
  self.new("\u{2797}" , [:heavy_division_sign]),
@@ -120,7 +120,7 @@ module Rumoji
120
120
  self.new("\u{274e}" , [:negative_squared_cross_mark]),
121
121
  self.new("\u{1f195}", [:new]),
122
122
  self.new("\u{1f196}", [:ng]),
123
- self.new("\u{0039}" , [:nine]),
123
+ self.new("\u{0039 20e3}" , [:nine]),
124
124
  self.new("\u{1f6b3}", [:no_bicycles]),
125
125
  self.new("\u{26d4}" , [:no_entry]),
126
126
  self.new("\u{1f6ab}", [:no_entry_sign]),
@@ -132,7 +132,7 @@ module Rumoji
132
132
  self.new("\u{1f17e}", [:o2]),
133
133
  self.new("\u{1f197}", [:ok]),
134
134
  self.new("\u{1f51b}", [:on]),
135
- self.new("\u{0031}" , [:one]),
135
+ self.new("\u{0031 20e3}" , [:one]),
136
136
  self.new("\u{26ce}" , [:ophiuchus]),
137
137
  self.new("\u{1f17f}", [:parking]),
138
138
  self.new("\u{303d}" , [:part_alternation_mark]),
@@ -152,9 +152,9 @@ module Rumoji
152
152
  self.new("\u{2650}" , [:sagittarius]),
153
153
  self.new("\u{264f}" , [:scorpius]),
154
154
  self.new("\u{3299}" , [:secret]),
155
- self.new("\u{0037}" , [:seven]),
155
+ self.new("\u{0037 20e3}" , [:seven]),
156
156
  self.new("\u{1f4f6}", [:signal_strength]),
157
- self.new("\u{0036}" , [:six]),
157
+ self.new("\u{0036 20e3}" , [:six]),
158
158
  self.new("\u{1f52f}", [:six_pointed_star]),
159
159
  self.new("\u{1f539}", [:small_blue_diamond]),
160
160
  self.new("\u{1f538}", [:small_orange_diamond]),
@@ -164,12 +164,12 @@ module Rumoji
164
164
  self.new("\u{1f198}", [:sos]),
165
165
  self.new("\u{1f523}", [:symbols]),
166
166
  self.new("\u{2649}" , [:taurus]),
167
- self.new("\u{0033}" , [:three]),
167
+ self.new("\u{0033 20e3}" , [:three]),
168
168
  self.new("\u{2122}" , [:tm]),
169
169
  self.new("\u{1f51d}", [:top]),
170
170
  self.new("\u{1f531}", [:trident]),
171
171
  self.new("\u{1f500}", [:twisted_rightwards_arrows]),
172
- self.new("\u{0032}" , [:two]),
172
+ self.new("\u{0032 20e3}" , [:two]),
173
173
  self.new("\u{1f239}", [:u5272]),
174
174
  self.new("\u{1f234}", [:u5408]),
175
175
  self.new("\u{1f23a}", [:u55b6]),
@@ -195,7 +195,7 @@ module Rumoji
195
195
  self.new("\u{1f533}", [:white_square_button]),
196
196
  self.new("\u{1f6ba}", [:womens]),
197
197
  self.new("\u{274c}" , [:x]),
198
- self.new("\u{0030}" , [:zero])
198
+ self.new("\u{0030 20e3}" , [:zero])
199
199
  ]
200
200
  end
201
201
  end
@@ -1,3 +1,3 @@
1
1
  module Rumoji
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -7,6 +7,8 @@ describe Rumoji do
7
7
  before do
8
8
  @poop = "πŸ’©"
9
9
  @smile = "πŸ˜„"
10
+ @zero = "0⃣"
11
+ @us = "πŸ‡ΊπŸ‡Έ"
10
12
  end
11
13
 
12
14
  describe "#encode" do
@@ -27,6 +29,29 @@ describe Rumoji do
27
29
  io = StringIO.new("#{@smile}")
28
30
  Rumoji.encode_io(io).string.must_equal ":smile:"
29
31
  end
32
+
33
+ describe "with multiple codepoints" do
34
+ it "transforms a stream" do
35
+ io1 = StringIO.new("#{@zero}")
36
+ io2 = StringIO.new("#{@us}")
37
+ Rumoji.encode_io(io1).string.must_equal ":zero:"
38
+ Rumoji.encode_io(io2).string.must_equal ":us:"
39
+ end
40
+
41
+ it "transforms a stream of many emoji" do
42
+ num = ":one::two::three::four::five::six::seven::eight::nine::hash:"
43
+ emoji = StringIO.new("1⃣2⃣3⃣4⃣5⃣6⃣7⃣8⃣9⃣#⃣")
44
+ Rumoji.encode_io(emoji).string.must_equal num
45
+ end
46
+
47
+ describe "with leading and trailing characters" do
48
+ it "is able to pull multipoint emoji out of a sequence" do
49
+ io = StringIO.new("An example of a multipoint emoji is the #{@us} flag.")
50
+ Rumoji.encode_io(io).string.must_equal "An example of a multipoint emoji is the :us: flag."
51
+ end
52
+ end
53
+ end
54
+
30
55
  end
31
56
 
32
57
  describe "#decode_io" do
@@ -34,5 +59,12 @@ describe Rumoji do
34
59
  io = StringIO.new(":poop:")
35
60
  Rumoji.decode_io(io).string.must_equal @poop
36
61
  end
62
+
63
+ describe "with multiple codepoints" do
64
+ it "decodes a stream" do
65
+ io = StringIO.new(":zero:")
66
+ Rumoji.decode_io(io).string.must_equal @zero
67
+ end
68
+ end
37
69
  end
38
70
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mark Wunsch
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-02 00:00:00.000000000 Z
11
+ date: 2013-08-27 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Transcode emoji utf-8 characters into emoji-cheat-sheet form
15
14
  email:
@@ -20,6 +19,7 @@ extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
21
  - .gitignore
22
+ - .travis.yml
23
23
  - Gemfile
24
24
  - LICENSE.txt
25
25
  - README.md
@@ -38,33 +38,26 @@ files:
38
38
  - spec/rumoji_spec.rb
39
39
  homepage: ''
40
40
  licenses: []
41
+ metadata: {}
41
42
  post_install_message:
42
43
  rdoc_options: []
43
44
  require_paths:
44
45
  - lib
45
46
  required_ruby_version: !ruby/object:Gem::Requirement
46
- none: false
47
47
  requirements:
48
- - - ! '>='
48
+ - - '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
- segments:
52
- - 0
53
- hash: -2903541076251608095
54
51
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
52
  requirements:
57
- - - ! '>='
53
+ - - '>='
58
54
  - !ruby/object:Gem::Version
59
55
  version: '0'
60
- segments:
61
- - 0
62
- hash: -2903541076251608095
63
56
  requirements: []
64
57
  rubyforge_project:
65
- rubygems_version: 1.8.23
58
+ rubygems_version: 2.0.0
66
59
  signing_key:
67
- specification_version: 3
60
+ specification_version: 4
68
61
  summary: Transcode emoji utf-8 characters into emoji-cheat-sheet form
69
62
  test_files:
70
63
  - spec/rumoji/emoji_spec.rb