rumoji 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8b7c62e0e1733933104c59ab3ac4d0312baafac
4
- data.tar.gz: 19ae2ccc6e4703995a5e12e2a5fc0579e0e399f7
3
+ metadata.gz: 937596f7150b11e8edda58fb25ce551aa5a09c34
4
+ data.tar.gz: f030bc4df7e3f826c3a16bfab65fd1fc16d8cb9d
5
5
  SHA512:
6
- metadata.gz: 29dfadb2c22ea87ba8a4d5f1d4cc7dc126168fcd5d3c72bacbbedfdbfa898fab0af4abd39c8559feb9707ea6dc26cb9e2ed79ebbc74e41ef536c35e6cd1c4209
7
- data.tar.gz: 3d56797e19ad1558e4a44198bfb2f6e2f11b35734ef7ecd2e8244232e87a6ad10d82395e0dba5ffdb5185804e98a7dd233161dbd2e617d7044fc71441f0a7f27
6
+ metadata.gz: 69dd6d823624ed3b57903db1568aeb357c40f78d1c97ca44600d8afb16a15093233c6da5afdfbd702fe358d130a939ce0c2750b4ff4443cb136f662856cc49d3
7
+ data.tar.gz: 1eed7329f0e7a5b2a8e69bda5a4b65fc0870d0b1059ea826a8800ff74a66cdcbea3228f82dbba4f8c16ab82d4dd73d686ba3eb50ebe110518bfec44f7197dff8
data/.travis.yml CHANGED
@@ -2,4 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - rbx-19mode
5
+ - 2.1.0
6
+ - rbx
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: rbx
data/Gemfile CHANGED
@@ -4,3 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rake'
7
+
8
+ platforms :rbx do
9
+ gem 'rubysl', '~> 2.0'
10
+ gem 'minitest'
11
+ end
data/lib/rumoji.rb CHANGED
@@ -14,41 +14,42 @@ module Rumoji
14
14
 
15
15
  # Transform a cheat-sheet code into an Emoji
16
16
  def decode(str)
17
- str.gsub(/:(\S?\w+):/) {|sym| Emoji.find($1.intern).to_s }
17
+ str.gsub(/:([^s:]?[\w-]+):/) {|sym| Emoji.find($1.intern).to_s }
18
18
  end
19
19
 
20
20
  def encode_io(readable, writeable=StringIO.new(""))
21
- codepoints = readable.each_codepoint
22
- previous_emoji = []
21
+ previous_codepoints = []
23
22
 
24
- codepoints.each_with_object(writeable) do |codepoint, writer|
23
+ readable.each_codepoint do |codepoint|
25
24
  possible_emoji = Emoji.select_by_codepoint(codepoint)
26
- last_emoji = previous_emoji.pop
27
25
 
28
- sequence = if last_emoji.nil? || !last_emoji.codepoints.include?(codepoint)
29
- if possible_emoji.empty? || last_emoji
30
- last_codepoint = last_emoji && last_emoji.codepoints.first
31
- sequence_from_codepoints(last_codepoint, codepoint)
26
+ sequence = if possible_emoji.empty?
27
+ # If this codepoint is not part of an emoji
28
+ # just write it back out, along with any previously stored codepoints.
29
+ dump_codepoints_to_string(previous_codepoints << codepoint)
30
+ elsif !possible_emoji.any?(&:multiple?)
31
+ # If this codepoint is part of an emoji, but not one
32
+ # that contains multiple codepoints, write out the
33
+ # first possiblity's cheat code and the previously stored codepoints
34
+ dump_codepoints_to_string(previous_codepoints) << possible_emoji.first.code
35
+ else
36
+ # This codepoint is a part of an emoji with multiple
37
+ # codepoints, so push it onto the stack.
38
+ previous_codepoints.push(codepoint)
39
+ # Check and see if this completes the emoji, otherwise,
40
+ # write out an empty string.
41
+ if found = possible_emoji.find {|e| e.codepoints.eql?(previous_codepoints) }
42
+ previous_codepoints.clear and found.code
32
43
  else
33
- multiple_codepoint_emoji = possible_emoji.select(&:multiple?)
34
- if multiple_codepoint_emoji.empty?
35
- possible_emoji.first.code
36
- else
37
- previous_emoji.concat(multiple_codepoint_emoji) ; ""
38
- end
44
+ ""
39
45
  end
40
- else
41
- last_emoji.code
42
46
  end
43
47
 
44
- writer.write sequence
48
+ writeable.write sequence
45
49
  end
46
50
 
47
- # If the last character was the beginning of a possible emoji, tack the
48
- # first codepoint onto the end.
49
- if last_emoji = previous_emoji.pop
50
- writeable.write sequence_from_codepoints(last_emoji.codepoints.first)
51
- end
51
+ # Write any remaining codepoints.
52
+ writeable.write dump_codepoints_to_string(previous_codepoints) if previous_codepoints.any?
52
53
 
53
54
  writeable
54
55
  end
@@ -62,9 +63,10 @@ module Rumoji
62
63
 
63
64
  private
64
65
 
65
- def sequence_from_codepoints(*codepoints)
66
- compacted = codepoints.flatten.compact
67
- compacted.pack("U" * compacted.size)
66
+ def dump_codepoints_to_string(codepoints)
67
+ codepoints.pack("U*").tap do
68
+ codepoints.clear
69
+ end
68
70
  end
69
71
 
70
72
  end
data/lib/rumoji/emoji.rb CHANGED
@@ -59,11 +59,12 @@ module Rumoji
59
59
  end
60
60
 
61
61
  def self.select_by_codepoint(codepoint)
62
- ALL.select {|emoji| emoji.codepoints.first.eql? codepoint }
62
+ ALL.select {|emoji| emoji.codepoints.include? codepoint }
63
63
  end
64
64
 
65
65
  def self.find_by_codepoint(codepoint)
66
66
  ALL.find {|emoji| emoji.hex == codepoint.to_s(16).upcase }
67
67
  end
68
+
68
69
  end
69
70
  end
@@ -94,7 +94,7 @@ module Rumoji
94
94
  self.new("\u{1F3B5}", [:musical_note]), # "music, being in good mood"
95
95
  self.new("\u{1F525}", [:fire], "FIRE"),
96
96
  # Poop
97
- self.new("\u{1F4A9}", [:hankey, :poop, :shit], "PILE OF POO"), # "dog dirt"
97
+ self.new("\u{1F4A9}", [:poop, :hankey, :shit], "PILE OF POO"), # "dog dirt"
98
98
  self.new("\u{1F44D}", [:thumbsup, :"+1"], "THUMBS UP SIGN"),
99
99
  self.new("\u{1F44E}", [:thumbsdown, :"-1"], "THUMBS DOWN SIGN"),
100
100
  self.new("\u{1F44C}", [:ok_hand], "OK HAND SIGN"),
@@ -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 20e3}" , [:eight]),
84
+ self.new("\u{0038 fe0f 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 20e3}" , [:five]),
90
- self.new("\u{0034 20e3}" , [:four]),
89
+ self.new("\u{0035 fe0f 20e3}" , [:five]),
90
+ self.new("\u{0034 fe0f 20e3}" , [:four]),
91
91
  self.new("\u{1f193}", [:free]),
92
92
  self.new("\u{264a}" , [:gemini]),
93
- self.new("\u{0023 20e3}" , [:hash]),
93
+ self.new("\u{0023 fe0f 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 20e3}" , [:nine]),
123
+ self.new("\u{0039 fe0f 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 20e3}" , [:one]),
135
+ self.new("\u{0031 fe0f 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 20e3}" , [:seven]),
155
+ self.new("\u{0037 fe0f 20e3}" , [:seven]),
156
156
  self.new("\u{1f4f6}", [:signal_strength]),
157
- self.new("\u{0036 20e3}" , [:six]),
157
+ self.new("\u{0036 fe0f 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 20e3}" , [:three]),
167
+ self.new("\u{0033 fe0f 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 20e3}" , [:two]),
172
+ self.new("\u{0032 fe0f 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 20e3}" , [:zero])
198
+ self.new("\u{0030 fe0f 20e3}" , [:zero])
199
199
  ]
200
200
  end
201
201
  end
@@ -1,3 +1,3 @@
1
1
  module Rumoji
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/spec/rumoji_spec.rb CHANGED
@@ -7,14 +7,16 @@ describe Rumoji do
7
7
  before do
8
8
  @poop = "💩"
9
9
  @smile = "😄"
10
- @zero = "0"
10
+ @zero = "0️⃣"
11
11
  @us = "🇺🇸"
12
+ @non_potable_water = "🚱"
12
13
  end
13
14
 
14
15
  describe "#encode" do
15
16
  it "transforms emoji into cheat-sheet form" do
16
17
  key = :smile
17
18
  Rumoji.encode(@smile).must_equal ":smile:"
19
+ Rumoji.encode("#{@smile}").must_equal ":smile:"
18
20
  end
19
21
  end
20
22
 
@@ -22,6 +24,14 @@ describe Rumoji do
22
24
  it "transforms a cheat-sheet code into an emoji" do
23
25
  Rumoji.decode(":poop:").must_equal @poop
24
26
  end
27
+
28
+ it "transforms a cheat-sheet code into an emoji with colon" do
29
+ Rumoji.decode("::poop:").must_equal ':' + @poop
30
+ end
31
+
32
+ it "transforms a cheat-sheet code with a dash into an emoji" do
33
+ Rumoji.decode(":non-potable_water:").must_equal @non_potable_water
34
+ end
25
35
  end
26
36
 
27
37
  describe "#encode_io" do
@@ -33,7 +43,6 @@ describe Rumoji do
33
43
  it "keeps codepoints that match the beginnings of multi-codepoint emoji" do
34
44
  text = "i like #hashtags and 1direction they are the #1 band. end with 9"
35
45
  io = StringIO.new(text)
36
-
37
46
  Rumoji.encode_io(io).string.must_equal text
38
47
  end
39
48
 
@@ -46,17 +55,30 @@ describe Rumoji do
46
55
  end
47
56
 
48
57
  it "transforms a stream of many emoji" do
49
- num = ":one::two::three::four::five::six::seven::eight::nine::hash:"
50
- emoji = StringIO.new("123456789⃣#⃣")
58
+ num = ":one: :two: :three: :four: :five: :six: :seven: :eight: :nine: :zero: :hash:"
59
+ emoji = StringIO.new"1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 0️⃣ #️⃣"
51
60
  Rumoji.encode_io(emoji).string.must_equal num
52
61
  end
53
62
 
63
+ it "does not encode double digits" do
64
+ num = ":zero: :one: :two: :three: :four: :five: :six: :seven: :eight: :nine: :hash:"
65
+ double_digits = StringIO.new("00 11 22 33 44 55 66 77 88 99 ##")
66
+ Rumoji.encode_io(double_digits).string.wont_equal num
67
+ end
68
+
54
69
  describe "with leading and trailing characters" do
55
70
  it "is able to pull multipoint emoji out of a sequence" do
56
71
  io = StringIO.new("An example of a multipoint emoji is the #{@us} flag.")
57
72
  Rumoji.encode_io(io).string.must_equal "An example of a multipoint emoji is the :us: flag."
58
73
  end
59
74
  end
75
+
76
+ describe "with trailing emoji" do
77
+ it "writes characters that are in a multipoint emoji followed by an emoji" do
78
+ io = StringIO.new "I would like 0#{@poop}"
79
+ Rumoji.encode_io(io).string.must_equal "I would like 0:poop:"
80
+ end
81
+ end
60
82
  end
61
83
 
62
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wunsch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Transcode emoji utf-8 characters into emoji-cheat-sheet form
14
14
  email:
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  requirements: []
57
57
  rubyforge_project:
58
- rubygems_version: 2.0.0
58
+ rubygems_version: 2.0.14
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: Transcode emoji utf-8 characters into emoji-cheat-sheet form