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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de978fd64342c2dd2b12cee0a86b0091481435fb
4
- data.tar.gz: 829b05c91801308ce59a65380d6e0a4894a82ce5
3
+ metadata.gz: e75050c917591b71a2bec6839ba773ce8db0b0a5
4
+ data.tar.gz: 932dbfc7d19c456d58d59403e8e4f79462f56373
5
5
  SHA512:
6
- metadata.gz: 7c1c6cc3e2f27120f9d8fed885be4947f50084eb454e318fa449f5e2c4133aa7fe8323c0255cdf7071a9b69e4087d620109f730f02fc3722787d6a6e727c48b8
7
- data.tar.gz: 3946512a880937497f8173e1b2ea6086480518beddc41d6ec83f2406036055e3098a9d0836bb06006f7657c763a6d9dd3c72a1524c26692d8a8a7746a365dc36
6
+ metadata.gz: 492d9986683f98be2f0e268445ddecbc976a372d06854b1a2858b9556f9627ea149a2fd39866fe0ec6e0d062c715e20824eee95ba0c8e89f958e1d3964722ba0
7
+ data.tar.gz: d7bd3e2ae36cd69be1693d617ba859ceb66c580f8dfb0d7bc719d089e140be749e7249f219c0bc2d3087daf071c3f64cdaaa9f08804868a42dd94be0e1e79cde
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ### 0.4.0
4
+
5
+ * Support Japanese Emojis (KDDI / SoftBank / DoCoMo) for Unicode
6
+
3
7
  ### 0.3.1
4
8
 
5
9
  * Add two Khmer blanks (U+17B4, U+17B5)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- characteristics (0.3.1)
4
+ characteristics (0.4.0)
5
5
  unicode-categories (~> 1.1, >= 1.1.2)
6
6
 
7
7
  GEM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AsciiCharacteristics < Characteristics
2
4
  BLANKS = [
3
5
  0x9,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class BinaryCharacteristics < Characteristics
2
4
  BLANKS = [
3
5
  0x9,
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Characteristics
2
- VERSION = "0.3.1".freeze
4
+ VERSION = "0.4.0".freeze
3
5
  end
@@ -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-*" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: characteristics
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
  - Jan Lelis