gsm_texting 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/compatibility_table.rb +276 -0
- data/lib/conversion_table.rb +40 -273
- data/lib/gsm_texting.rb +25 -8
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6371fec8250ebd69c530c37b12c254e61595bc6bb6dcb2a465e9e59042c1a77f
|
4
|
+
data.tar.gz: 0762b3325b76b835d0b602f3940686c664f9b0e54d5b5b90c5d1968fa1e122ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 934653921b5a3066f027d09b510ecaf040d54ce41c51f61fc77192a37a99819e3777d2e6fdfd5cdb0c01ca6662482d8ecee2cc81849f74107caff0a5c68e5241
|
7
|
+
data.tar.gz: 79a077cd060273434d1e2b4f10b61f185f426bc5e3be1d90bffe7043be4282d167b3fc1b4fa4a9214ab81f7d1dd9a45399e81b3175e9c61928bc888b79439c3f
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require 'character_constants'
|
2
|
+
|
3
|
+
module CompatibilityTable
|
4
|
+
include CharacterConstants
|
5
|
+
|
6
|
+
# https://www.twilio.com/docs/sms/services/copilot-smart-encoding-char-list
|
7
|
+
# Converts UNICODE characters to GSM compatible ones
|
8
|
+
COMPATIBILITY_TABLE = {
|
9
|
+
0x00ab => DQ, # «
|
10
|
+
0x00bb => DQ, # »
|
11
|
+
0x02ba => DQ, # ʺ
|
12
|
+
0x02ee => DQ, # ˮ
|
13
|
+
0x201f => DQ, # ‟
|
14
|
+
0x275d => DQ, # ❝
|
15
|
+
0x275e => DQ, # ❞
|
16
|
+
0x301d => DQ, #
|
17
|
+
0x301e => DQ, # 〞
|
18
|
+
0xff02 => DQ, #
|
19
|
+
0x2018 => SQ, # ‘
|
20
|
+
0x2019 => SQ, # ’
|
21
|
+
0x02bb => SQ, # ʻ
|
22
|
+
0x02c8 => SQ, # ˈ
|
23
|
+
0x02bc => SQ, # ʼ
|
24
|
+
0x02bd => SQ, # ʽ
|
25
|
+
0x02b9 => SQ, # ʹ
|
26
|
+
0xff07 => SQ, #
|
27
|
+
0x00b4 => SQ, # ´
|
28
|
+
0x02ca => SQ, # ˊ
|
29
|
+
0x0060 => SQ, # `
|
30
|
+
0x02cb => SQ, # ˋ
|
31
|
+
0x275b => SQ, # ❛
|
32
|
+
0x275c => SQ, # ❜
|
33
|
+
0x0313 => SQ, #
|
34
|
+
0x0314 => SQ, #
|
35
|
+
0xfe10 => SQ, #
|
36
|
+
0xfe11 => SQ, #
|
37
|
+
0x00f7 => '/', # ÷
|
38
|
+
0x00bc => '1/4', # ¼
|
39
|
+
0x00bd => '1/2', # ½
|
40
|
+
0x00be => '3/4', # ¾
|
41
|
+
0x29f8 => '/', # ⧸
|
42
|
+
0x0337 => '/', #
|
43
|
+
0x0338 => '/', #
|
44
|
+
0x2044 => '/', # ⁄
|
45
|
+
0x2215 => '/', # ∕
|
46
|
+
0xff0f => '/', # /
|
47
|
+
0x29f9 => BS, # ⧹
|
48
|
+
0x29f5 => BS, # ⧵
|
49
|
+
0x20e5 => BS, #
|
50
|
+
0xfe68 => BS, #
|
51
|
+
0xff3c => BS, # \
|
52
|
+
0x0332 => '_', #
|
53
|
+
0xff3f => '_', # _
|
54
|
+
0x20d2 => '|', #
|
55
|
+
0x20d3 => '|', #
|
56
|
+
0x2223 => '|', # ∣
|
57
|
+
0xff5c => '|', #
|
58
|
+
0x23b8 => '|', # ⎸
|
59
|
+
0x23b9 => '|', #
|
60
|
+
0x23d0 => '|', # ⏐
|
61
|
+
0x239c => '|', # ⎜
|
62
|
+
0x239f => '|', # ⎟
|
63
|
+
0x23bc => '-', # ⎼
|
64
|
+
0x23bd => '-', # ⎽
|
65
|
+
0x2015 => '-', # ―
|
66
|
+
0xfe63 => '-', # ﹣
|
67
|
+
0xff0d => '-', # -
|
68
|
+
0x2010 => '-', # ‐
|
69
|
+
0x2043 => '-', # ⁃
|
70
|
+
0xfe6b => '@', # ﹫
|
71
|
+
0xff20 => '@', # @
|
72
|
+
0xfe69 => '$', # ﹩
|
73
|
+
0xff04 => '$', # $
|
74
|
+
0x01c3 => '!', # ǃ
|
75
|
+
0xfe15 => '!', #
|
76
|
+
0xfe57 => '!', #
|
77
|
+
0xff01 => '!', # !
|
78
|
+
0xfe5f => '#', # ﹟
|
79
|
+
0xff03 => '#', # #
|
80
|
+
0xfe6a => '%', # ﹪
|
81
|
+
0xff05 => '%', # %
|
82
|
+
0xfe60 => '&', # ﹠
|
83
|
+
0xff06 => '&', # &
|
84
|
+
0x0326 => ',', #
|
85
|
+
0xfe50 => ',', # ﹐
|
86
|
+
0xfe51 => ',', # ﹑
|
87
|
+
0xff0c => ',', # ,
|
88
|
+
0xff64 => ',', # 、
|
89
|
+
0x2768 => '(', # ❨
|
90
|
+
0x276a => '(', # ❪
|
91
|
+
0xfe59 => '(', # ﹙
|
92
|
+
0xff08 => '(', #
|
93
|
+
0x27ee => '(', # ⟮
|
94
|
+
0x2985 => '(', # ⦅
|
95
|
+
0x2769 => ')', # ❩
|
96
|
+
0x276b => ')', # ❫
|
97
|
+
0xfe5a => ')', # ﹚
|
98
|
+
0xff09 => ')', # )
|
99
|
+
0x27ef => ')', # ⟯
|
100
|
+
0x2986 => ')', # ⦆
|
101
|
+
0x204e => '*', # ⁎
|
102
|
+
0x2217 => '*', # ∗
|
103
|
+
0x229b => '*', # ⊛
|
104
|
+
0x2722 => '*', # ✢
|
105
|
+
0x2723 => '*', # ✣
|
106
|
+
0x2724 => '*', # ✤
|
107
|
+
0x2725 => '*', # ✥
|
108
|
+
0x2731 => '*', # ✱
|
109
|
+
0x2732 => '*', # ✲
|
110
|
+
0x2733 => '*', # ✳
|
111
|
+
0x273a => '*', # ✺
|
112
|
+
0x273b => '*', # ✻
|
113
|
+
0x273c => '*', # ✼
|
114
|
+
0x273d => '*', # ✽
|
115
|
+
0x2743 => '*', # ❃
|
116
|
+
0x2749 => '*', # ❉
|
117
|
+
0x274a => '*', # ❊
|
118
|
+
0x274b => '*', # ❋
|
119
|
+
0x29c6 => '*', # ⧆
|
120
|
+
0xfe61 => '*', # ﹡
|
121
|
+
0xff0a => '*', # *
|
122
|
+
0x02d6 => '+', # ˖
|
123
|
+
0xfe62 => '+', # ﹢
|
124
|
+
0xff0b => '+', # +
|
125
|
+
0x3002 => '.', # 。
|
126
|
+
0xfe52 => '.', # ﹒
|
127
|
+
0xff0e => '.', # .
|
128
|
+
0xff61 => '.', # 。
|
129
|
+
0xff10 => '0', # 0
|
130
|
+
0xff11 => '1', # 1
|
131
|
+
0xff12 => '2', # 2
|
132
|
+
0xff13 => '3', # 3
|
133
|
+
0xff14 => '4', # 4
|
134
|
+
0xff15 => '5', # 5
|
135
|
+
0xff16 => '6', # 6
|
136
|
+
0xff17 => '7', # 7
|
137
|
+
0xff18 => '8', # 8
|
138
|
+
0xff19 => '9', # 9
|
139
|
+
0x02d0 => ':', # ː
|
140
|
+
0x02f8 => ':', # ˸
|
141
|
+
0x2982 => ':', # ˸
|
142
|
+
0xa789 => ':', # ꞉
|
143
|
+
0xfe13 => ':', # ︓
|
144
|
+
0xff1a => ':', # :
|
145
|
+
0x204f => ';', # ⁏
|
146
|
+
0xfe14 => ';', # ︔
|
147
|
+
0xfe54 => ';', # ﹔
|
148
|
+
0xff1b => ';', # ;
|
149
|
+
0xfe64 => '<', # ﹤
|
150
|
+
0xff1c => '<', # <
|
151
|
+
0x0347 => '=', #
|
152
|
+
0xa78a => '=', # ꞊
|
153
|
+
0xfe66 => '=', # ﹦
|
154
|
+
0xff1d => '=', # =
|
155
|
+
0xfe65 => '>', # ﹥
|
156
|
+
0xff1e => '>', # >
|
157
|
+
0xfe16 => '?', # ︖
|
158
|
+
0xfe56 => '?', # ﹖
|
159
|
+
0xff1f => '?', # ?
|
160
|
+
0xff21 => 'A', # A
|
161
|
+
0x1d00 => 'A', # ᴀ
|
162
|
+
0xff22 => 'B', # B
|
163
|
+
0x0299 => 'B', # ʙ
|
164
|
+
0xff23 => 'C', # C
|
165
|
+
0x1d04 => 'C', # ᴄ
|
166
|
+
0xff24 => 'D', # D
|
167
|
+
0x1d05 => 'D', # ᴅ
|
168
|
+
0xff25 => 'E', # E
|
169
|
+
0x1d07 => 'E', # ᴇ
|
170
|
+
0xff26 => 'F', # F
|
171
|
+
0xA730 => 'F', # ꜰ
|
172
|
+
0xff27 => 'G', # G
|
173
|
+
0x0262 => 'G', # ɢ
|
174
|
+
0xff28 => 'H', # H
|
175
|
+
0x029c => 'H', # ʜ
|
176
|
+
0xff29 => 'I', # I
|
177
|
+
0x026a => 'I', # ɪ
|
178
|
+
0xff2a => 'J', # J
|
179
|
+
0x1d0a => 'J', # ᴊ
|
180
|
+
0xff2b => 'K', # K
|
181
|
+
0x1d0b => 'K', # ᴋ
|
182
|
+
0xff2c => 'L', # L
|
183
|
+
0x029f => 'L', # ʟ
|
184
|
+
0xff2d => 'M', # M
|
185
|
+
0x1d0d => 'M', # ᴍ
|
186
|
+
0xff2e => 'N', # N
|
187
|
+
0x0274 => 'N', # ɴ
|
188
|
+
0xff2f => 'O', # O
|
189
|
+
0x1d0f => 'O', # ᴏ
|
190
|
+
0xff30 => 'P', # P
|
191
|
+
0x1d18 => 'P', # ᴘ
|
192
|
+
0xff31 => 'Q', # Q
|
193
|
+
0xff32 => 'R', # R
|
194
|
+
0x0280 => 'R', # ʀ
|
195
|
+
0xff33 => 'S', # S
|
196
|
+
0xa731 => 'S', # ꜱ
|
197
|
+
0xff34 => 'T', # T
|
198
|
+
0x1d1b => 'T', # ᴛ
|
199
|
+
0xff35 => 'U', # U
|
200
|
+
0x1d1c => 'U', # ᴜ
|
201
|
+
0xff36 => 'V', # V
|
202
|
+
0x1d20 => 'V', # ᴠ
|
203
|
+
0xff37 => 'W', # W
|
204
|
+
0x1d21 => 'W', # ᴡ
|
205
|
+
0xff38 => 'X', # X
|
206
|
+
0xff39 => 'Y', # Y
|
207
|
+
0x028f => 'Y', # ʏ
|
208
|
+
0xff3a => 'Z', # Z
|
209
|
+
0x1d22 => 'Z', # ᴢ
|
210
|
+
0x02c6 => '^', # ˆ
|
211
|
+
0x0302 => '^', #
|
212
|
+
0xff3e => '^', # ^
|
213
|
+
0x1dcd => '^', #
|
214
|
+
0x2774 => '{', # ❴
|
215
|
+
0xfe5b => '{', # ﹛
|
216
|
+
0xff5b => '{', #
|
217
|
+
0x2775 => '}', # ❵
|
218
|
+
0xfe5c => '}', # ﹜
|
219
|
+
0xff5d => '}', # }
|
220
|
+
0xff3b => '[', #
|
221
|
+
0xff3d => ']', # ]
|
222
|
+
0x02dc => '~', # ˜
|
223
|
+
0x02f7 => '~', # ˷
|
224
|
+
0x0303 => '~', #
|
225
|
+
0x0330 => '~', #
|
226
|
+
0x0334 => '~', #
|
227
|
+
0x223c => '~', # ∼
|
228
|
+
0xff5e => '~', # ~
|
229
|
+
0x00a0 => SP,
|
230
|
+
0x2000 => SP,
|
231
|
+
0x2001 => SP,
|
232
|
+
0x2002 => SP,
|
233
|
+
0x2003 => SP,
|
234
|
+
0x2004 => SP,
|
235
|
+
0x2005 => SP,
|
236
|
+
0x2006 => SP,
|
237
|
+
0x2007 => SP,
|
238
|
+
0x2008 => SP,
|
239
|
+
0x2009 => SP,
|
240
|
+
0x200a => SP,
|
241
|
+
0x3000 => SP,
|
242
|
+
0x008d => SP,
|
243
|
+
0x009f => SP,
|
244
|
+
0x0080 => SP,
|
245
|
+
0x0090 => SP,
|
246
|
+
0x009b => SP,
|
247
|
+
0x0010 => SP,
|
248
|
+
0x0009 => SP,
|
249
|
+
0x0000 => SP,
|
250
|
+
0x0003 => SP,
|
251
|
+
0x0004 => SP,
|
252
|
+
0x0017 => SP,
|
253
|
+
0x0019 => SP,
|
254
|
+
0x0011 => SP,
|
255
|
+
0x0012 => SP,
|
256
|
+
0x0013 => SP,
|
257
|
+
0x0014 => SP,
|
258
|
+
0x2017 => '_', # ‗
|
259
|
+
0x2014 => '-', # —
|
260
|
+
0x2013 => '-', # –
|
261
|
+
0x201a => SQ, # ‚
|
262
|
+
0x202f => SP,
|
263
|
+
0x2039 => '>', # ‹
|
264
|
+
0x203A => '<', # ›
|
265
|
+
0x203c => '!!', # ‼
|
266
|
+
0x201e => DQ, # „
|
267
|
+
0x201d => DQ, # ”
|
268
|
+
0x201c => DQ, # “
|
269
|
+
0x201b => SQ, # ‛
|
270
|
+
0x2026 => '...', # …
|
271
|
+
0x2028 => SP,
|
272
|
+
0x2029 => SP,
|
273
|
+
0x205f => SP,
|
274
|
+
0x2060 => SP
|
275
|
+
}.freeze
|
276
|
+
end
|
data/lib/conversion_table.rb
CHANGED
@@ -1,276 +1,43 @@
|
|
1
|
-
require 'character_constants'
|
2
|
-
|
3
1
|
module ConversionTable
|
4
|
-
include CharacterConstants
|
5
|
-
|
6
|
-
# https://www.twilio.com/docs/sms/services/copilot-smart-encoding-char-list
|
7
|
-
# Converts UNICODE characters to GSM compatible ones
|
8
2
|
CONVERSION_TABLE = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
0x20e5 => BS, #
|
50
|
-
0xfe68 => BS, #
|
51
|
-
0xff3c => BS, # \
|
52
|
-
0x0332 => '_', #
|
53
|
-
0xff3f => '_', # _
|
54
|
-
0x20d2 => '|', #
|
55
|
-
0x20d3 => '|', #
|
56
|
-
0x2223 => '|', # ∣
|
57
|
-
0xff5c => '|', #
|
58
|
-
0x23b8 => '|', # ⎸
|
59
|
-
0x23b9 => '|', #
|
60
|
-
0x23d0 => '|', # ⏐
|
61
|
-
0x239c => '|', # ⎜
|
62
|
-
0x239f => '|', # ⎟
|
63
|
-
0x23bc => '-', # ⎼
|
64
|
-
0x23bd => '-', # ⎽
|
65
|
-
0x2015 => '-', # ―
|
66
|
-
0xfe63 => '-', # ﹣
|
67
|
-
0xff0d => '-', # -
|
68
|
-
0x2010 => '-', # ‐
|
69
|
-
0x2043 => '-', # ⁃
|
70
|
-
0xfe6b => '@', # ﹫
|
71
|
-
0xff20 => '@', # @
|
72
|
-
0xfe69 => '$', # ﹩
|
73
|
-
0xff04 => '$', # $
|
74
|
-
0x01c3 => '!', # ǃ
|
75
|
-
0xfe15 => '!', #
|
76
|
-
0xfe57 => '!', #
|
77
|
-
0xff01 => '!', # !
|
78
|
-
0xfe5f => '#', # ﹟
|
79
|
-
0xff03 => '#', # #
|
80
|
-
0xfe6a => '%', # ﹪
|
81
|
-
0xff05 => '%', # %
|
82
|
-
0xfe60 => '&', # ﹠
|
83
|
-
0xff06 => '&', # &
|
84
|
-
0x0326 => ',', #
|
85
|
-
0xfe50 => ',', # ﹐
|
86
|
-
0xfe51 => ',', # ﹑
|
87
|
-
0xff0c => ',', # ,
|
88
|
-
0xff64 => ',', # 、
|
89
|
-
0x2768 => '(', # ❨
|
90
|
-
0x276a => '(', # ❪
|
91
|
-
0xfe59 => '(', # ﹙
|
92
|
-
0xff08 => '(', #
|
93
|
-
0x27ee => '(', # ⟮
|
94
|
-
0x2985 => '(', # ⦅
|
95
|
-
0x2769 => ')', # ❩
|
96
|
-
0x276b => ')', # ❫
|
97
|
-
0xfe5a => ')', # ﹚
|
98
|
-
0xff09 => ')', # )
|
99
|
-
0x27ef => ')', # ⟯
|
100
|
-
0x2986 => ')', # ⦆
|
101
|
-
0x204e => '*', # ⁎
|
102
|
-
0x2217 => '*', # ∗
|
103
|
-
0x229b => '*', # ⊛
|
104
|
-
0x2722 => '*', # ✢
|
105
|
-
0x2723 => '*', # ✣
|
106
|
-
0x2724 => '*', # ✤
|
107
|
-
0x2725 => '*', # ✥
|
108
|
-
0x2731 => '*', # ✱
|
109
|
-
0x2732 => '*', # ✲
|
110
|
-
0x2733 => '*', # ✳
|
111
|
-
0x273a => '*', # ✺
|
112
|
-
0x273b => '*', # ✻
|
113
|
-
0x273c => '*', # ✼
|
114
|
-
0x273d => '*', # ✽
|
115
|
-
0x2743 => '*', # ❃
|
116
|
-
0x2749 => '*', # ❉
|
117
|
-
0x274a => '*', # ❊
|
118
|
-
0x274b => '*', # ❋
|
119
|
-
0x29c6 => '*', # ⧆
|
120
|
-
0xfe61 => '*', # ﹡
|
121
|
-
0xff0a => '*', # *
|
122
|
-
0x02d6 => '+', # ˖
|
123
|
-
0xfe62 => '+', # ﹢
|
124
|
-
0xff0b => '+', # +
|
125
|
-
0x3002 => '.', # 。
|
126
|
-
0xfe52 => '.', # ﹒
|
127
|
-
0xff0e => '.', # .
|
128
|
-
0xff61 => '.', # 。
|
129
|
-
0xff10 => '0', # 0
|
130
|
-
0xff11 => '1', # 1
|
131
|
-
0xff12 => '2', # 2
|
132
|
-
0xff13 => '3', # 3
|
133
|
-
0xff14 => '4', # 4
|
134
|
-
0xff15 => '5', # 5
|
135
|
-
0xff16 => '6', # 6
|
136
|
-
0xff17 => '7', # 7
|
137
|
-
0xff18 => '8', # 8
|
138
|
-
0xff19 => '9', # 9
|
139
|
-
0x02d0 => ':', # ː
|
140
|
-
0x02f8 => ':', # ˸
|
141
|
-
0x2982 => ':', # ˸
|
142
|
-
0xa789 => ':', # ꞉
|
143
|
-
0xfe13 => ':', # ︓
|
144
|
-
0xff1a => ':', # :
|
145
|
-
0x204f => ';', # ⁏
|
146
|
-
0xfe14 => ';', # ︔
|
147
|
-
0xfe54 => ';', # ﹔
|
148
|
-
0xff1b => ';', # ;
|
149
|
-
0xfe64 => '<', # ﹤
|
150
|
-
0xff1c => '<', # <
|
151
|
-
0x0347 => '=', #
|
152
|
-
0xa78a => '=', # ꞊
|
153
|
-
0xfe66 => '=', # ﹦
|
154
|
-
0xff1d => '=', # =
|
155
|
-
0xfe65 => '>', # ﹥
|
156
|
-
0xff1e => '>', # >
|
157
|
-
0xfe16 => '?', # ︖
|
158
|
-
0xfe56 => '?', # ﹖
|
159
|
-
0xff1f => '?', # ?
|
160
|
-
0xff21 => 'A', # A
|
161
|
-
0x1d00 => 'A', # ᴀ
|
162
|
-
0xff22 => 'B', # B
|
163
|
-
0x0299 => 'B', # ʙ
|
164
|
-
0xff23 => 'C', # C
|
165
|
-
0x1d04 => 'C', # ᴄ
|
166
|
-
0xff24 => 'D', # D
|
167
|
-
0x1d05 => 'D', # ᴅ
|
168
|
-
0xff25 => 'E', # E
|
169
|
-
0x1d07 => 'E', # ᴇ
|
170
|
-
0xff26 => 'F', # F
|
171
|
-
0xA730 => 'F', # ꜰ
|
172
|
-
0xff27 => 'G', # G
|
173
|
-
0x0262 => 'G', # ɢ
|
174
|
-
0xff28 => 'H', # H
|
175
|
-
0x029c => 'H', # ʜ
|
176
|
-
0xff29 => 'I', # I
|
177
|
-
0x026a => 'I', # ɪ
|
178
|
-
0xff2a => 'J', # J
|
179
|
-
0x1d0a => 'J', # ᴊ
|
180
|
-
0xff2b => 'K', # K
|
181
|
-
0x1d0b => 'K', # ᴋ
|
182
|
-
0xff2c => 'L', # L
|
183
|
-
0x029f => 'L', # ʟ
|
184
|
-
0xff2d => 'M', # M
|
185
|
-
0x1d0d => 'M', # ᴍ
|
186
|
-
0xff2e => 'N', # N
|
187
|
-
0x0274 => 'N', # ɴ
|
188
|
-
0xff2f => 'O', # O
|
189
|
-
0x1d0f => 'O', # ᴏ
|
190
|
-
0xff30 => 'P', # P
|
191
|
-
0x1d18 => 'P', # ᴘ
|
192
|
-
0xff31 => 'Q', # Q
|
193
|
-
0xff32 => 'R', # R
|
194
|
-
0x0280 => 'R', # ʀ
|
195
|
-
0xff33 => 'S', # S
|
196
|
-
0xa731 => 'S', # ꜱ
|
197
|
-
0xff34 => 'T', # T
|
198
|
-
0x1d1b => 'T', # ᴛ
|
199
|
-
0xff35 => 'U', # U
|
200
|
-
0x1d1c => 'U', # ᴜ
|
201
|
-
0xff36 => 'V', # V
|
202
|
-
0x1d20 => 'V', # ᴠ
|
203
|
-
0xff37 => 'W', # W
|
204
|
-
0x1d21 => 'W', # ᴡ
|
205
|
-
0xff38 => 'X', # X
|
206
|
-
0xff39 => 'Y', # Y
|
207
|
-
0x028f => 'Y', # ʏ
|
208
|
-
0xff3a => 'Z', # Z
|
209
|
-
0x1d22 => 'Z', # ᴢ
|
210
|
-
0x02c6 => '^', # ˆ
|
211
|
-
0x0302 => '^', #
|
212
|
-
0xff3e => '^', # ^
|
213
|
-
0x1dcd => '^', #
|
214
|
-
0x2774 => '{', # ❴
|
215
|
-
0xfe5b => '{', # ﹛
|
216
|
-
0xff5b => '{', #
|
217
|
-
0x2775 => '}', # ❵
|
218
|
-
0xfe5c => '}', # ﹜
|
219
|
-
0xff5d => '}', # }
|
220
|
-
0xff3b => '[', #
|
221
|
-
0xff3d => ']', # ]
|
222
|
-
0x02dc => '~', # ˜
|
223
|
-
0x02f7 => '~', # ˷
|
224
|
-
0x0303 => '~', #
|
225
|
-
0x0330 => '~', #
|
226
|
-
0x0334 => '~', #
|
227
|
-
0x223c => '~', # ∼
|
228
|
-
0xff5e => '~', # ~
|
229
|
-
0x00a0 => SP,
|
230
|
-
0x2000 => SP,
|
231
|
-
0x2001 => SP,
|
232
|
-
0x2002 => SP,
|
233
|
-
0x2003 => SP,
|
234
|
-
0x2004 => SP,
|
235
|
-
0x2005 => SP,
|
236
|
-
0x2006 => SP,
|
237
|
-
0x2007 => SP,
|
238
|
-
0x2008 => SP,
|
239
|
-
0x2009 => SP,
|
240
|
-
0x200a => SP,
|
241
|
-
0x3000 => SP,
|
242
|
-
0x008d => SP,
|
243
|
-
0x009f => SP,
|
244
|
-
0x0080 => SP,
|
245
|
-
0x0090 => SP,
|
246
|
-
0x009b => SP,
|
247
|
-
0x0010 => SP,
|
248
|
-
0x0009 => SP,
|
249
|
-
0x0000 => SP,
|
250
|
-
0x0003 => SP,
|
251
|
-
0x0004 => SP,
|
252
|
-
0x0017 => SP,
|
253
|
-
0x0019 => SP,
|
254
|
-
0x0011 => SP,
|
255
|
-
0x0012 => SP,
|
256
|
-
0x0013 => SP,
|
257
|
-
0x0014 => SP,
|
258
|
-
0x2017 => '_', # ‗
|
259
|
-
0x2014 => '-', # —
|
260
|
-
0x2013 => '-', # –
|
261
|
-
0x201a => SQ, # ‚
|
262
|
-
0x202f => SP,
|
263
|
-
0x2039 => '>', # ‹
|
264
|
-
0x203A => '<', # ›
|
265
|
-
0x203c => '!!', # ‼
|
266
|
-
0x201e => DQ, # „
|
267
|
-
0x201d => DQ, # ”
|
268
|
-
0x201c => DQ, # “
|
269
|
-
0x201b => SQ, # ‛
|
270
|
-
0x2026 => '...', # …
|
271
|
-
0x2028 => SP,
|
272
|
-
0x2029 => SP,
|
273
|
-
0x205f => SP,
|
274
|
-
0x2060 => SP
|
275
|
-
}.freeze
|
3
|
+
0x00c0 => "A", # À
|
4
|
+
0x00c1 => "A", # Á
|
5
|
+
0x00c2 => "A", # Â
|
6
|
+
0x00c3 => "A", # Ã
|
7
|
+
0x00c8 => "E", # È
|
8
|
+
0x00ca => "E", # Ê
|
9
|
+
0x00cb => "E", # Ë
|
10
|
+
0x00cc => "I", # Ì
|
11
|
+
0x00cd => "I", # Í
|
12
|
+
0x00cf => "I", # Ï
|
13
|
+
0x00d0 => "D", # Ð
|
14
|
+
0x00d2 => "O", # Ò
|
15
|
+
0x00d3 => "O", # Ó
|
16
|
+
0x00d4 => "O", # Ô
|
17
|
+
0x00d5 => "O", # Õ
|
18
|
+
0x00d7 => "x", # ×
|
19
|
+
0x00d9 => "U", # Ù
|
20
|
+
0x00da => "U", # Ú
|
21
|
+
0x00db => "U", # Û
|
22
|
+
0x00dd => "Y", # Ý
|
23
|
+
0x00de => "th", # Þ
|
24
|
+
0x00e1 => "a", # á
|
25
|
+
0x00e2 => "a", # â
|
26
|
+
0x00e3 => "a", # ã
|
27
|
+
0x00e7 => "c", # ç
|
28
|
+
0x00ea => "e", # ê
|
29
|
+
0x00eb => "e", # ë
|
30
|
+
0x00ed => "i", # í
|
31
|
+
0x00ee => "i", # î
|
32
|
+
0x00ef => "i", # ï
|
33
|
+
0x00f0 => "d", # ð
|
34
|
+
0x00f3 => "o", # ó
|
35
|
+
0x00f4 => "o", # ô
|
36
|
+
0x00f5 => "o", # õ
|
37
|
+
0x00fa => "u", # ú
|
38
|
+
0x00fb => "u", # û
|
39
|
+
0x00fd => "y", # ý
|
40
|
+
0x00fe => "th", # þ
|
41
|
+
0x00ff => "y" # ÿ
|
42
|
+
}
|
276
43
|
end
|
data/lib/gsm_texting.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'character_constants'
|
2
|
+
require 'compatibility_table'
|
2
3
|
require 'conversion_table'
|
3
4
|
|
4
5
|
module GSMTexting
|
5
6
|
include CharacterConstants
|
7
|
+
include CompatibilityTable
|
6
8
|
include ConversionTable
|
7
9
|
extend self
|
8
10
|
|
@@ -42,19 +44,34 @@ module GSMTexting
|
|
42
44
|
end
|
43
45
|
|
44
46
|
# Convert unicode chars to GSM-7 compatible equivalents if possible
|
45
|
-
def encode(str, replace_char: nil)
|
47
|
+
def encode(str, transliterate: false, replace_char: nil)
|
46
48
|
return if str.nil?
|
47
|
-
|
48
|
-
unless replace_char && can_encode?(replace_char)
|
49
|
-
replace_char = DEFAULT_REPLACE_CHAR
|
50
|
-
end
|
49
|
+
replace_char = canonicalize_replace_char(replace_char)
|
51
50
|
|
52
51
|
str.unpack("U*").map { |char|
|
53
|
-
gsm_compatible_char = CONVERSION_TABLE[char]
|
54
52
|
utf8_char = char.chr(Encoding::UTF_8)
|
55
|
-
gsm_char = can_encode?(utf8_char) ? utf8_char : replace_char
|
56
53
|
|
57
|
-
|
54
|
+
compatible_char = compatible_char_for(char)
|
55
|
+
transformed_char = transformed_char_for(char) if transliterate
|
56
|
+
gsm_char_for(compatible_char || transformed_char || utf8_char, replace_char)
|
58
57
|
}.join
|
59
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def canonicalize_replace_char(char)
|
63
|
+
char && can_encode?(char) ? char : DEFAULT_REPLACE_CHAR
|
64
|
+
end
|
65
|
+
|
66
|
+
def compatible_char_for(char)
|
67
|
+
COMPATIBILITY_TABLE[char]
|
68
|
+
end
|
69
|
+
|
70
|
+
def transformed_char_for(char)
|
71
|
+
CONVERSION_TABLE[char]
|
72
|
+
end
|
73
|
+
|
74
|
+
def gsm_char_for(char, replace_char)
|
75
|
+
can_encode?(char) ? char : replace_char
|
76
|
+
end
|
60
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gsm_texting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jorge Kalmbach
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/character_constants.rb
|
20
|
+
- lib/compatibility_table.rb
|
20
21
|
- lib/conversion_table.rb
|
21
22
|
- lib/gsm_texting.rb
|
22
23
|
homepage: https://github.com/kalmbach/gsm_texting
|