e4u 0.0.4 → 0.0.6

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.6
data/lib/e4u.rb CHANGED
@@ -1,5 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
-
3
1
  require 'e4u/base'
4
2
  require 'e4u/docomo'
5
3
  require 'e4u/kddi'
@@ -78,7 +78,7 @@ module E4U
78
78
  end
79
79
 
80
80
  def cp932
81
- return NKF.nkf('-Wsm0x', fallback_text) if fallback?
81
+ return NKF.nkf('-m0xWs --oc=CP932', fallback_text) if fallback?
82
82
  hex = unicode.sub(/\A[\>\*\+]/, '')
83
83
  raise if hex.size == 0
84
84
  chr = hex.split(/\+/, -1).map{ |ch| unicode_to_cp932(ch.hex) }.pack('n*')
@@ -5,7 +5,7 @@ module E4U
5
5
  private
6
6
 
7
7
  def path
8
- File.expand_path(File.join('..', '..', 'data', 'docomo', 'carrier_data.xml'), File.dirname(__FILE__))
8
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'docomo', 'carrier_data.xml'))
9
9
  end
10
10
 
11
11
  def emojinize object
@@ -5,7 +5,7 @@ module E4U
5
5
  private
6
6
 
7
7
  def path
8
- File.expand_path(File.join('..', '..', 'data', 'emoji4unicode.xml'), File.dirname(__FILE__))
8
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'emoji4unicode.xml'))
9
9
  end
10
10
 
11
11
  def emojinize object
@@ -38,15 +38,15 @@ module E4U
38
38
  Google::Emoji.new self.merge(:unicode => self[:google])
39
39
  end
40
40
 
41
+ def text_fallback
42
+ self[:text_fallback] || self[:text_repr] || [0x3013].pack('U')
43
+ end
44
+
41
45
  private
42
46
 
43
47
  def attribute_with_fallback_text type
44
48
  attributes = { :unicode => self[type] }
45
- unless attributes[:unicode]
46
- attributes[:fallback_text] = self[:text_fallback]
47
- attributes[:fallback_text] ||= self[:text_repr]
48
- attributes[:fallback_text] ||= [0x3013].pack('U')
49
- end
49
+ attributes[:fallback_text] = text_fallback unless attributes[:unicode]
50
50
  attributes
51
51
  end
52
52
  end
@@ -5,7 +5,7 @@ module E4U
5
5
  private
6
6
 
7
7
  def path
8
- File.expand_path(File.join('..', '..', 'data', 'kddi', 'carrier_data.xml'), File.dirname(__FILE__))
8
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'kddi', 'carrier_data.xml'))
9
9
  end
10
10
 
11
11
  def emojinize object
@@ -5,7 +5,7 @@ module E4U
5
5
  private
6
6
 
7
7
  def path
8
- File.expand_path(File.join('..', '..', 'data', 'softbank', 'carrier_data.xml'), File.dirname(__FILE__))
8
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'softbank', 'carrier_data.xml'))
9
9
  end
10
10
 
11
11
  def emojinize object
@@ -24,6 +24,30 @@ module E4U
24
24
  def number; nil end
25
25
  def unicode; nil end
26
26
 
27
+ def webcode
28
+ return NKF.nkf('-m0xWs --oc=CP932', fallback_text) if fallback?
29
+ hex = unicode.sub(/\A[\>\*\+]/, '')
30
+ raise if hex.size == 0
31
+ buf = []
32
+ prev = nil
33
+ hex.split(/\+/, -1).each do |e|
34
+ code = e.hex
35
+ high = (code & 0x0700) >> 8
36
+ low = (code & 0x00FF) + 32
37
+ page = %w(G E F O P Q)[high]
38
+ raise unless page
39
+ unless page == prev
40
+ buf << "\x0F" if buf.size > 0
41
+ buf << "\x1B\x24#{page}"
42
+ end
43
+ buf << low.chr
44
+ prev = page
45
+ end
46
+ buf << "\x0F"
47
+ str = buf.join
48
+ #str.force_encoding(???) if str.respond_to? :force_encoding
49
+ end
50
+
27
51
  private
28
52
 
29
53
  def unicode_to_cp932 octet
@@ -32,6 +32,17 @@ describe E4U::Google do
32
32
  emj[:unicode].should == '2600'
33
33
  end
34
34
 
35
+ # TODO: 紛らわしい
36
+ it "text_fallbackでfallback_textが返ってくること" do
37
+ @google.each do |e|
38
+ except = e[:text_fallback]
39
+ except ||= e[:text_repr]
40
+ except ||= [0x3013].pack('U')
41
+
42
+ e.text_fallback.should == except
43
+ end
44
+ end
45
+
35
46
  it "docomo_emojiでE4U::DoCoMo::Emojiが返ってくること" do
36
47
  de = @google.find{ |e| e[:id] == '000' }.docomo_emoji
37
48
  de.should be_instance_of E4U::DoCoMo::Emoji
@@ -44,7 +55,7 @@ describe E4U::Google do
44
55
  '4B8' => [[0xE669, 0xE6EF].pack('U*'), [0xF8CA, 0xF994].pack('n*')] }.each do |id, (utf8, sjis)|
45
56
  de = @google.find{ |e| e[:id] == id }.docomo_emoji
46
57
  de.utf8.should == utf8
47
- de.sjis.should == sjis
58
+ de.sjis.dump.should == sjis.dump
48
59
  end
49
60
  end
50
61
 
@@ -69,22 +80,14 @@ describe E4U::Google do
69
80
  it "utf8でfallback_textが返ってくること" do
70
81
  @google.each do |e|
71
82
  next if e[:docomo]
72
- except = e[:text_fallback]
73
- except ||= e[:text_repr]
74
- except ||= [0x3013].pack('U')
75
-
76
- e.docomo_emoji.utf8.should == except
83
+ e.docomo_emoji.utf8.should == e.text_fallback
77
84
  end
78
85
  end
79
86
 
80
87
  it "sjisでfallback_textが返ってくること" do
81
88
  @google.each do |e|
82
89
  next if e[:docomo]
83
- except = e[:text_fallback]
84
- except ||= e[:text_repr]
85
- except ||= [0x3013].pack('U')
86
-
87
- e.docomo_emoji.sjis.should == NKF.nkf('-Wsm0x', except)
90
+ e.docomo_emoji.sjis.should == NKF.nkf('-m0xWs --oc=CP932', e.text_fallback)
88
91
  end
89
92
  end
90
93
  end
@@ -100,7 +103,7 @@ describe E4U::Google do
100
103
  { '331' => [[0xE471, 0xE5B1].pack('U*'), [0xF649, 0xF7CE].pack('n*')], }.each do |id, (utf8, sjis)|
101
104
  ke = @google.find{ |e| e[:id] == id }.kddi_emoji
102
105
  ke.utf8.should == utf8
103
- ke.sjis.should == sjis
106
+ ke.sjis.dump.should == sjis.dump
104
107
  end
105
108
  end
106
109
 
@@ -108,7 +111,7 @@ describe E4U::Google do
108
111
  { '331' => [[0xEF49, 0xF0CE].pack('U*'), [0xF649, 0xF7CE].pack('n*')], }.each do |id, (utf8, sjis)|
109
112
  de = @google.find{ |e| e[:id] == id }.kddiweb_emoji
110
113
  de.utf8.should == utf8
111
- de.sjis.should == sjis
114
+ de.sjis.dump.should == sjis.dump
112
115
  end
113
116
  end
114
117
 
@@ -133,22 +136,14 @@ describe E4U::Google do
133
136
  it "utf8でfallback_textが返ってくること" do
134
137
  @google.each do |e|
135
138
  next if e[:kddi]
136
- except = e[:text_fallback]
137
- except ||= e[:text_repr]
138
- except ||= [0x3013].pack('U')
139
-
140
- e.kddi_emoji.utf8.should == except
139
+ e.kddi_emoji.utf8.should == e.text_fallback
141
140
  end
142
141
  end
143
142
 
144
143
  it "sjisでSJISのfallback_textが返ってくること" do
145
144
  @google.each do |e|
146
145
  next if e[:kddi]
147
- except = e[:text_fallback]
148
- except ||= e[:text_repr]
149
- except ||= [0x3013].pack('U')
150
-
151
- e.kddi_emoji.sjis.should == NKF.nkf('-Wsm0x', except)
146
+ e.kddi_emoji.sjis.should == NKF.nkf('-m0xWs --oc=CP932', e.text_fallback)
152
147
  end
153
148
  end
154
149
  end
@@ -161,12 +156,19 @@ describe E4U::Google do
161
156
  end
162
157
 
163
158
  it "Softbankの複合絵文字が返ってくること" do
164
- { '00F' => [[0xE04A, 0xE049].pack('U*'), [0xF98B, 0xF98A].pack('n*')],
165
- '331' => [[0xE415, 0xE331].pack('U*'), [0xFB55, 0xF9D1].pack('n*')],
166
- '824' => [[0xE103, 0xE328].pack('U*'), [0xF743, 0xF9C8].pack('n*')], }.each do |id, (utf8, sjis)|
159
+ { '00F' => [[0xE04A, 0xE049].pack('U*'),
160
+ [0xF98B, 0xF98A].pack('n*'),
161
+ "\x1B$Gji\x0F"],
162
+ '331' => [[0xE415, 0xE331].pack('U*'),
163
+ [0xFB55, 0xF9D1].pack('n*'),
164
+ "\x1B$P5\x0F\x1B$OQ\x0F"],
165
+ '824' => [[0xE103, 0xE328].pack('U*'),
166
+ [0xF743, 0xF9C8].pack('n*'),
167
+ "\x1B$E#\x0F\x1B$OH\x0F"], }.each do |id, (utf8, sjis, webcode)|
167
168
  se = @google.find{ |e| e[:id] == id }.softbank_emoji
168
169
  se.utf8.should == utf8
169
- se.sjis.should == sjis
170
+ se.sjis.dump.should == sjis.dump
171
+ se.webcode.should == webcode
170
172
  end
171
173
  end
172
174
 
@@ -191,22 +193,14 @@ describe E4U::Google do
191
193
  it "utf8でfallback_textが返ってくること" do
192
194
  @google.each do |e|
193
195
  next if e[:softbank]
194
- except = e[:text_fallback]
195
- except ||= e[:text_repr]
196
- except ||= [0x3013].pack('U')
197
-
198
- e.softbank_emoji.utf8.should == except
196
+ e.softbank_emoji.utf8.should == e.text_fallback
199
197
  end
200
198
  end
201
199
 
202
200
  it "sjisでSJISのfallback_textが返ってくること" do
203
201
  @google.each do |e|
204
202
  next if e[:softbank]
205
- except = e[:text_fallback]
206
- except ||= e[:text_repr]
207
- except ||= [0x3013].pack('U')
208
-
209
- e.softbank_emoji.sjis.should == NKF.nkf('-Wsm0x', except)
203
+ e.softbank_emoji.sjis.should == NKF.nkf('-m0xWs --oc=CP932', e.text_fallback)
210
204
  end
211
205
  end
212
206
  end
@@ -275,12 +269,7 @@ describe E4U::Google do
275
269
  @google.each do |e|
276
270
  next unless e[:google]
277
271
  next if e[:docomo]
278
-
279
- except = e[:text_fallback]
280
- except ||= e[:text_repr]
281
- except ||= [0x3013].pack('U')
282
-
283
- e.google_emoji.translate(:docomo).utf8.should == except
272
+ e.google_emoji.translate(:docomo).utf8.should == e.text_fallback
284
273
  end
285
274
  end
286
275
  end
@@ -57,5 +57,9 @@ describe E4U::Softbank do
57
57
  it "alternate?が返ってくること" do
58
58
  @emj.alternate?.should be_false
59
59
  end
60
+
61
+ it "webcodeが返ってくること" do
62
+ @emj.webcode.should == "\x1B\x24Gj\x0F"
63
+ end
60
64
  end
61
65
  end
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --loadby mtime
3
+ --reverse
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e4u
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - fistfvck
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-08 00:00:00 +09:00
12
+ date: 2010-01-15 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency