characteristics 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/characteristics/ascii.rb +2 -0
- data/lib/characteristics/binary.rb +2 -0
- data/lib/characteristics/byte.rb +8 -12
- data/lib/characteristics/unicode.rb +26 -0
- data/lib/characteristics/version.rb +3 -1
- data/lib/characteristics.rb +41 -1
- data/spec/characteristics_spec.rb +21 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e75050c917591b71a2bec6839ba773ce8db0b0a5
|
4
|
+
data.tar.gz: 932dbfc7d19c456d58d59403e8e4f79462f56373
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492d9986683f98be2f0e268445ddecbc976a372d06854b1a2858b9556f9627ea149a2fd39866fe0ec6e0d062c715e20824eee95ba0c8e89f958e1d3964722ba0
|
7
|
+
data.tar.gz: d7bd3e2ae36cd69be1693d617ba859ceb66c580f8dfb0d7bc719d089e140be749e7249f219c0bc2d3087daf071c3f64cdaaa9f08804868a42dd94be0e1e79cde
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/characteristics/byte.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ByteCharacteristics < Characteristics
|
2
4
|
HAS_C1 = /^(ISO-8859-|TIS-620)/
|
3
5
|
|
@@ -151,18 +153,6 @@ class ByteCharacteristics < Characteristics
|
|
151
153
|
@ord = char.ord
|
152
154
|
end
|
153
155
|
|
154
|
-
def encoding_has_c0?
|
155
|
-
true
|
156
|
-
end
|
157
|
-
|
158
|
-
def encoding_has_delete?
|
159
|
-
true
|
160
|
-
end
|
161
|
-
|
162
|
-
def encoding_has_c1?
|
163
|
-
!!(HAS_C1 =~ @encoding_name)
|
164
|
-
end
|
165
|
-
|
166
156
|
def unicode?
|
167
157
|
false
|
168
158
|
end
|
@@ -196,4 +186,10 @@ class ByteCharacteristics < Characteristics
|
|
196
186
|
def format?
|
197
187
|
FORMATS[@ord] =~ @encoding_name
|
198
188
|
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def encoding_has_c1?
|
193
|
+
!!(HAS_C1 =~ @encoding_name)
|
194
|
+
end
|
199
195
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "unicode/categories"
|
2
4
|
|
3
5
|
class UnicodeCharacteristics < Characteristics
|
@@ -111,4 +113,28 @@ class UnicodeCharacteristics < Characteristics
|
|
111
113
|
def format?
|
112
114
|
@is_valid && @category == "Cf"
|
113
115
|
end
|
116
|
+
|
117
|
+
def kddi?
|
118
|
+
encoding_has_kddi? && ( @ord >= 0xE468 && @ord <= 0xE5DF ||
|
119
|
+
@ord >= 0xEA80 && @ord <= 0xEB8E )
|
120
|
+
end
|
121
|
+
|
122
|
+
def softbank?
|
123
|
+
encoding_has_softbank? && ( @ord >= 0xE001 && @ord <= 0xE05A ||
|
124
|
+
@ord >= 0xE101 && @ord <= 0xE15A ||
|
125
|
+
@ord >= 0xE201 && @ord <= 0xE25A ||
|
126
|
+
@ord >= 0xE301 && @ord <= 0xE34D ||
|
127
|
+
@ord >= 0xE401 && @ord <= 0xE44C ||
|
128
|
+
@ord >= 0xE501 && @ord <= 0xE53E )
|
129
|
+
end
|
130
|
+
|
131
|
+
def docomo?
|
132
|
+
encoding_has_docomo? && ( @ord >= 0xE63E && @ord <= 0xE757 )
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def encoding_has_c1?
|
138
|
+
true
|
139
|
+
end
|
114
140
|
end
|
data/lib/characteristics.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "characteristics/version"
|
2
4
|
|
3
5
|
require_relative "characteristics/ascii"
|
@@ -12,7 +14,7 @@ class Characteristics
|
|
12
14
|
:ascii
|
13
15
|
when "ASCII-8BIT"
|
14
16
|
:binary
|
15
|
-
when /^UTF
|
17
|
+
when /^UTF-?/
|
16
18
|
:unicode
|
17
19
|
when /^ISO-8859-/, /^Windows-125/, /^(IBM|CP85)/, /^mac/, 'TIS-620', 'Windows-874', /^KOI8-/
|
18
20
|
:byte
|
@@ -66,4 +68,42 @@ class Characteristics
|
|
66
68
|
|
67
69
|
def format?
|
68
70
|
end
|
71
|
+
|
72
|
+
# private use emojis
|
73
|
+
def kddi?
|
74
|
+
end
|
75
|
+
|
76
|
+
# private use emojis
|
77
|
+
def softbank?
|
78
|
+
end
|
79
|
+
|
80
|
+
# private use emojis
|
81
|
+
def docomo?
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def encoding_has_kddi?
|
87
|
+
@encoding_name.end_with? "KDDI"
|
88
|
+
end
|
89
|
+
|
90
|
+
def encoding_has_softbank?
|
91
|
+
@encoding_name.end_with? "SoftBank"
|
92
|
+
end
|
93
|
+
|
94
|
+
def encoding_has_docomo?
|
95
|
+
@encoding_name.end_with? "DoCoMo"
|
96
|
+
end
|
97
|
+
|
98
|
+
def encoding_has_c0?
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
102
|
+
def encoding_has_delete?
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
def encoding_has_c1?
|
107
|
+
false
|
108
|
+
end
|
69
109
|
end
|
@@ -23,7 +23,7 @@ describe Characteristics do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe UnicodeCharacteristics do
|
26
|
-
describe "UTF
|
26
|
+
describe "UTF*" do
|
27
27
|
let(:encoding) { "UTF-8" }
|
28
28
|
|
29
29
|
it "is valid or not" do
|
@@ -53,6 +53,26 @@ describe Characteristics do
|
|
53
53
|
refute format? "\x21"
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe "Japanese Emojis" do
|
58
|
+
it "can be a KDDI emoji" do
|
59
|
+
encoding = "UTF8-KDDI"
|
60
|
+
assert Characteristics.create("\uE468".force_encoding(encoding)).kddi?
|
61
|
+
refute Characteristics.create("A".force_encoding(encoding)).kddi?
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can be a SoftBank emoji" do
|
65
|
+
encoding = "UTF8-SoftBank"
|
66
|
+
assert Characteristics.create("\uE001".force_encoding(encoding)).softbank?
|
67
|
+
refute Characteristics.create("A".force_encoding(encoding)).softbank?
|
68
|
+
end
|
69
|
+
|
70
|
+
it "can be a DoCoMo emoji" do
|
71
|
+
encoding = "UTF8-DoCoMo"
|
72
|
+
assert Characteristics.create("\uE63E".force_encoding(encoding)).docomo?
|
73
|
+
refute Characteristics.create("A".force_encoding(encoding)).docomo?
|
74
|
+
end
|
75
|
+
end
|
56
76
|
end
|
57
77
|
|
58
78
|
describe BinaryCharacteristics do
|