unicode-blocks 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +324 -0
- data/Rakefile +37 -0
- data/data/blocks.marshal.gz +0 -0
- data/lib/unicode/blocks.rb +28 -0
- data/lib/unicode/blocks/constants.rb +9 -0
- data/lib/unicode/blocks/index.rb +7 -0
- data/lib/unicode/blocks/string_ext.rb +8 -0
- data/spec/unicode_blocks_spec.rb +47 -0
- data/unicode-blocks.gemspec +21 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b38f5df5fa5d73b475767811ca6d9c10c696843
|
4
|
+
data.tar.gz: c2d05210ad71351f206a61fa3caba9ae634c1fa2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4635d1b9bd0e9dfd88aacf2dd6290255f5130d17efa9d7f615f18e70262822617d6bde4403d430762c80de8fc3f32a095747090eedba375ea0cd34ebac3726f9
|
7
|
+
data.tar.gz: ae83eaedb564caa8c3cda41c4b412c271e8844c22b0ee0ad44d9269da4ef860549edaa31dddfbed992524c9af9e330e366c2195c9b0ddb682ddf05e29f081121
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
|
4
|
+
script: bundle exec ruby spec/unicode_blocks_spec.rb
|
5
|
+
|
6
|
+
rvm:
|
7
|
+
- 2.3.0
|
8
|
+
- 2.2
|
9
|
+
- 2.1
|
10
|
+
- ruby-head
|
11
|
+
- rbx-2
|
12
|
+
- jruby-head
|
13
|
+
- jruby-9.0.5.0
|
14
|
+
|
15
|
+
cache:
|
16
|
+
- bundler
|
17
|
+
|
18
|
+
matrix:
|
19
|
+
allow_failures:
|
20
|
+
- rvm: jruby-head
|
21
|
+
- rvm: rbx-2
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at opensource@janlelis.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Jan Lelis, mail@janlelis.de
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,324 @@
|
|
1
|
+
# Unicode::Blocks [![[version]](https://badge.fury.io/rb/unicode-blocks.svg)](http://badge.fury.io/rb/unicode-blocks) [![[travis]](https://travis-ci.org/janlelis/unicode-blocks.png)](https://travis-ci.org/janlelis/unicode-blocks)
|
2
|
+
|
3
|
+
Each unicode character belongs to a [block](https://en.wikipedia.org/wiki/Unicode_block). This gem returns the all blocks asociated with the given string.
|
4
|
+
|
5
|
+
Unicode version: **8.0.0**
|
6
|
+
|
7
|
+
Supported Rubies: **2.3**, **2.2**, **2.1**
|
8
|
+
|
9
|
+
## Gemfile
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "unicode-blocks"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require "unicode/blocks"
|
19
|
+
|
20
|
+
# All blocks of a string
|
21
|
+
Unicode::Blocks.blocks("Abc") # => ["Basic Latin"]
|
22
|
+
Unicode::Blocks.blocks("СC") # => ["Cyrillic", "Basic Latin"]
|
23
|
+
Unicode::Blocks.blocks("⧉⪥⟤") # => ["Miscellaneous Mathematical Symbols-A",
|
24
|
+
"Miscellaneous Mathematical Symbols-B",
|
25
|
+
"Supplemental Mathematical Operators"]
|
26
|
+
|
27
|
+
# Also aliased as .of
|
28
|
+
Unicode::Blocks.of("🃉🂹") # => ["Playing Cards"]
|
29
|
+
Unicode::Blocks.of("\u{10c50}") # => ["No_Block"]
|
30
|
+
|
31
|
+
# Single character
|
32
|
+
Unicode::Blocks.block("☼") # => "Miscellaneous Symbols"
|
33
|
+
```
|
34
|
+
|
35
|
+
The list of blocks is always sorted alphabetically.
|
36
|
+
|
37
|
+
## Hints
|
38
|
+
|
39
|
+
### Regex Matching
|
40
|
+
|
41
|
+
If you have a string and want to match a substring/character from a specific Unicode block, you actually won't need this gem. Instead, you can use the [Regexp Unicode Property Syntax `\p{}`](http://ruby-doc.org/core-2.3.0/Regexp.html#class-Regexp-label-Character+Properties) with blocks by prefixing the block name with "In":
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
"⧉⪥⟤".scan(/\p{In Miscellaneous Mathematical Symbols-B}/) # => ["⧉"]
|
45
|
+
```
|
46
|
+
|
47
|
+
### Block Names
|
48
|
+
|
49
|
+
You can retrieve all block names (except for **No_Block**) like this:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require "unicode/blocks"
|
53
|
+
puts Unicode::Blocks.names
|
54
|
+
|
55
|
+
# # # Output # # #
|
56
|
+
|
57
|
+
Basic Latin
|
58
|
+
Latin-1 Supplement
|
59
|
+
Latin Extended-A
|
60
|
+
Latin Extended-B
|
61
|
+
IPA Extensions
|
62
|
+
Spacing Modifier Letters
|
63
|
+
Combining Diacritical Marks
|
64
|
+
Greek and Coptic
|
65
|
+
Cyrillic
|
66
|
+
Cyrillic Supplement
|
67
|
+
Armenian
|
68
|
+
Hebrew
|
69
|
+
Arabic
|
70
|
+
Syriac
|
71
|
+
Arabic Supplement
|
72
|
+
Thaana
|
73
|
+
NKo
|
74
|
+
Samaritan
|
75
|
+
Mandaic
|
76
|
+
Arabic Extended-A
|
77
|
+
Devanagari
|
78
|
+
Bengali
|
79
|
+
Gurmukhi
|
80
|
+
Gujarati
|
81
|
+
Oriya
|
82
|
+
Tamil
|
83
|
+
Telugu
|
84
|
+
Kannada
|
85
|
+
Malayalam
|
86
|
+
Sinhala
|
87
|
+
Thai
|
88
|
+
Lao
|
89
|
+
Tibetan
|
90
|
+
Myanmar
|
91
|
+
Georgian
|
92
|
+
Hangul Jamo
|
93
|
+
Ethiopic
|
94
|
+
Ethiopic Supplement
|
95
|
+
Cherokee
|
96
|
+
Unified Canadian Aboriginal Syllabics
|
97
|
+
Ogham
|
98
|
+
Runic
|
99
|
+
Tagalog
|
100
|
+
Hanunoo
|
101
|
+
Buhid
|
102
|
+
Tagbanwa
|
103
|
+
Khmer
|
104
|
+
Mongolian
|
105
|
+
Unified Canadian Aboriginal Syllabics Extended
|
106
|
+
Limbu
|
107
|
+
Tai Le
|
108
|
+
New Tai Lue
|
109
|
+
Khmer Symbols
|
110
|
+
Buginese
|
111
|
+
Tai Tham
|
112
|
+
Combining Diacritical Marks Extended
|
113
|
+
Balinese
|
114
|
+
Sundanese
|
115
|
+
Batak
|
116
|
+
Lepcha
|
117
|
+
Ol Chiki
|
118
|
+
Sundanese Supplement
|
119
|
+
Vedic Extensions
|
120
|
+
Phonetic Extensions
|
121
|
+
Phonetic Extensions Supplement
|
122
|
+
Combining Diacritical Marks Supplement
|
123
|
+
Latin Extended Additional
|
124
|
+
Greek Extended
|
125
|
+
General Punctuation
|
126
|
+
Superscripts and Subscripts
|
127
|
+
Currency Symbols
|
128
|
+
Combining Diacritical Marks for Symbols
|
129
|
+
Letterlike Symbols
|
130
|
+
Number Forms
|
131
|
+
Arrows
|
132
|
+
Mathematical Operators
|
133
|
+
Miscellaneous Technical
|
134
|
+
Control Pictures
|
135
|
+
Optical Character Recognition
|
136
|
+
Enclosed Alphanumerics
|
137
|
+
Box Drawing
|
138
|
+
Block Elements
|
139
|
+
Geometric Shapes
|
140
|
+
Miscellaneous Symbols
|
141
|
+
Dingbats
|
142
|
+
Miscellaneous Mathematical Symbols-A
|
143
|
+
Supplemental Arrows-A
|
144
|
+
Braille Patterns
|
145
|
+
Supplemental Arrows-B
|
146
|
+
Miscellaneous Mathematical Symbols-B
|
147
|
+
Supplemental Mathematical Operators
|
148
|
+
Miscellaneous Symbols and Arrows
|
149
|
+
Glagolitic
|
150
|
+
Latin Extended-C
|
151
|
+
Coptic
|
152
|
+
Georgian Supplement
|
153
|
+
Tifinagh
|
154
|
+
Ethiopic Extended
|
155
|
+
Cyrillic Extended-A
|
156
|
+
Supplemental Punctuation
|
157
|
+
CJK Radicals Supplement
|
158
|
+
Kangxi Radicals
|
159
|
+
Ideographic Description Characters
|
160
|
+
CJK Symbols and Punctuation
|
161
|
+
Hiragana
|
162
|
+
Katakana
|
163
|
+
Bopomofo
|
164
|
+
Hangul Compatibility Jamo
|
165
|
+
Kanbun
|
166
|
+
Bopomofo Extended
|
167
|
+
CJK Strokes
|
168
|
+
Katakana Phonetic Extensions
|
169
|
+
Enclosed CJK Letters and Months
|
170
|
+
CJK Compatibility
|
171
|
+
CJK Unified Ideographs Extension A
|
172
|
+
Yijing Hexagram Symbols
|
173
|
+
CJK Unified Ideographs
|
174
|
+
Yi Syllables
|
175
|
+
Yi Radicals
|
176
|
+
Lisu
|
177
|
+
Vai
|
178
|
+
Cyrillic Extended-B
|
179
|
+
Bamum
|
180
|
+
Modifier Tone Letters
|
181
|
+
Latin Extended-D
|
182
|
+
Syloti Nagri
|
183
|
+
Common Indic Number Forms
|
184
|
+
Phags-pa
|
185
|
+
Saurashtra
|
186
|
+
Devanagari Extended
|
187
|
+
Kayah Li
|
188
|
+
Rejang
|
189
|
+
Hangul Jamo Extended-A
|
190
|
+
Javanese
|
191
|
+
Myanmar Extended-B
|
192
|
+
Cham
|
193
|
+
Myanmar Extended-A
|
194
|
+
Tai Viet
|
195
|
+
Meetei Mayek Extensions
|
196
|
+
Ethiopic Extended-A
|
197
|
+
Latin Extended-E
|
198
|
+
Cherokee Supplement
|
199
|
+
Meetei Mayek
|
200
|
+
Hangul Syllables
|
201
|
+
Hangul Jamo Extended-B
|
202
|
+
High Surrogates
|
203
|
+
High Private Use Surrogates
|
204
|
+
Low Surrogates
|
205
|
+
Private Use Area
|
206
|
+
CJK Compatibility Ideographs
|
207
|
+
Alphabetic Presentation Forms
|
208
|
+
Arabic Presentation Forms-A
|
209
|
+
Variation Selectors
|
210
|
+
Vertical Forms
|
211
|
+
Combining Half Marks
|
212
|
+
CJK Compatibility Forms
|
213
|
+
Small Form Variants
|
214
|
+
Arabic Presentation Forms-B
|
215
|
+
Halfwidth and Fullwidth Forms
|
216
|
+
Specials
|
217
|
+
Linear B Syllabary
|
218
|
+
Linear B Ideograms
|
219
|
+
Aegean Numbers
|
220
|
+
Ancient Greek Numbers
|
221
|
+
Ancient Symbols
|
222
|
+
Phaistos Disc
|
223
|
+
Lycian
|
224
|
+
Carian
|
225
|
+
Coptic Epact Numbers
|
226
|
+
Old Italic
|
227
|
+
Gothic
|
228
|
+
Old Permic
|
229
|
+
Ugaritic
|
230
|
+
Old Persian
|
231
|
+
Deseret
|
232
|
+
Shavian
|
233
|
+
Osmanya
|
234
|
+
Elbasan
|
235
|
+
Caucasian Albanian
|
236
|
+
Linear A
|
237
|
+
Cypriot Syllabary
|
238
|
+
Imperial Aramaic
|
239
|
+
Palmyrene
|
240
|
+
Nabataean
|
241
|
+
Hatran
|
242
|
+
Phoenician
|
243
|
+
Lydian
|
244
|
+
Meroitic Hieroglyphs
|
245
|
+
Meroitic Cursive
|
246
|
+
Kharoshthi
|
247
|
+
Old South Arabian
|
248
|
+
Old North Arabian
|
249
|
+
Manichaean
|
250
|
+
Avestan
|
251
|
+
Inscriptional Parthian
|
252
|
+
Inscriptional Pahlavi
|
253
|
+
Psalter Pahlavi
|
254
|
+
Old Turkic
|
255
|
+
Old Hungarian
|
256
|
+
Rumi Numeral Symbols
|
257
|
+
Brahmi
|
258
|
+
Kaithi
|
259
|
+
Sora Sompeng
|
260
|
+
Chakma
|
261
|
+
Mahajani
|
262
|
+
Sharada
|
263
|
+
Sinhala Archaic Numbers
|
264
|
+
Khojki
|
265
|
+
Multani
|
266
|
+
Khudawadi
|
267
|
+
Grantha
|
268
|
+
Tirhuta
|
269
|
+
Siddham
|
270
|
+
Modi
|
271
|
+
Takri
|
272
|
+
Ahom
|
273
|
+
Warang Citi
|
274
|
+
Pau Cin Hau
|
275
|
+
Cuneiform
|
276
|
+
Cuneiform Numbers and Punctuation
|
277
|
+
Early Dynastic Cuneiform
|
278
|
+
Egyptian Hieroglyphs
|
279
|
+
Anatolian Hieroglyphs
|
280
|
+
Bamum Supplement
|
281
|
+
Mro
|
282
|
+
Bassa Vah
|
283
|
+
Pahawh Hmong
|
284
|
+
Miao
|
285
|
+
Kana Supplement
|
286
|
+
Duployan
|
287
|
+
Shorthand Format Controls
|
288
|
+
Byzantine Musical Symbols
|
289
|
+
Musical Symbols
|
290
|
+
Ancient Greek Musical Notation
|
291
|
+
Tai Xuan Jing Symbols
|
292
|
+
Counting Rod Numerals
|
293
|
+
Mathematical Alphanumeric Symbols
|
294
|
+
Sutton SignWriting
|
295
|
+
Mende Kikakui
|
296
|
+
Arabic Mathematical Alphabetic Symbols
|
297
|
+
Mahjong Tiles
|
298
|
+
Domino Tiles
|
299
|
+
Playing Cards
|
300
|
+
Enclosed Alphanumeric Supplement
|
301
|
+
Enclosed Ideographic Supplement
|
302
|
+
Miscellaneous Symbols and Pictographs
|
303
|
+
Emoticons
|
304
|
+
Ornamental Dingbats
|
305
|
+
Transport and Map Symbols
|
306
|
+
Alchemical Symbols
|
307
|
+
Geometric Shapes Extended
|
308
|
+
Supplemental Arrows-C
|
309
|
+
Supplemental Symbols and Pictographs
|
310
|
+
CJK Unified Ideographs Extension B
|
311
|
+
CJK Unified Ideographs Extension C
|
312
|
+
CJK Unified Ideographs Extension D
|
313
|
+
CJK Unified Ideographs Extension E
|
314
|
+
CJK Compatibility Ideographs Supplement
|
315
|
+
Tags
|
316
|
+
Variation Selectors Supplement
|
317
|
+
Supplementary Private Use Area-A
|
318
|
+
Supplementary Private Use Area-B
|
319
|
+
```
|
320
|
+
|
321
|
+
## MIT License
|
322
|
+
|
323
|
+
- Copyright (C) 2016 Jan Lelis <http://janlelis.com>. Released under the MIT license.
|
324
|
+
- Unicode data: http://www.unicode.org/copyright.html#Exhibit1
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# # #
|
2
|
+
# Get gemspec info
|
3
|
+
|
4
|
+
gemspec_file = Dir['*.gemspec'].first
|
5
|
+
gemspec = eval File.read(gemspec_file), binding, gemspec_file
|
6
|
+
info = "#{gemspec.name} | #{gemspec.version} | " \
|
7
|
+
"#{gemspec.runtime_dependencies.size} dependencies | " \
|
8
|
+
"#{gemspec.files.size} files"
|
9
|
+
|
10
|
+
# # #
|
11
|
+
# Gem build and install task
|
12
|
+
|
13
|
+
desc info
|
14
|
+
task :gem do
|
15
|
+
puts info + "\n\n"
|
16
|
+
print " "; sh "gem build #{gemspec_file}"
|
17
|
+
FileUtils.mkdir_p 'pkg'
|
18
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
19
|
+
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
|
20
|
+
end
|
21
|
+
|
22
|
+
# # #
|
23
|
+
# Start an IRB session with the gem loaded
|
24
|
+
|
25
|
+
desc "#{gemspec.name} | IRB"
|
26
|
+
task :irb do
|
27
|
+
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# # #
|
31
|
+
# Run Specs
|
32
|
+
|
33
|
+
desc "#{gemspec.name} | Spec"
|
34
|
+
task :spec do
|
35
|
+
sh "for file in spec/*.rb; do ruby $file; done"
|
36
|
+
end
|
37
|
+
task default: :spec
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "blocks/constants"
|
2
|
+
|
3
|
+
module Unicode
|
4
|
+
module Blocks
|
5
|
+
def self.blocks(string)
|
6
|
+
res = []
|
7
|
+
string.each_char{ |char|
|
8
|
+
block_name = block(char)
|
9
|
+
res << block_name unless res.include?(block_name)
|
10
|
+
}
|
11
|
+
res.sort
|
12
|
+
end
|
13
|
+
class << self; alias of blocks; end
|
14
|
+
|
15
|
+
def self.block(char)
|
16
|
+
require_relative 'blocks/index' unless defined? ::Unicode::Blocks::INDEX
|
17
|
+
codepoint = char.unpack("U")[0] or raise(ArgumentError, "Unicode::Blocks.block must be given a valid char")
|
18
|
+
block_info = INDEX.bsearch{ |block_info| codepoint <= block_info[1] }
|
19
|
+
codepoint >= block_info[0] ? block_info[2] : "No_Block"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.names
|
23
|
+
require_relative 'blocks/index' unless defined? ::Unicode::Blocks::INDEX
|
24
|
+
INDEX.map(&:last)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "../lib/unicode/blocks"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
describe Unicode::Blocks do
|
5
|
+
describe ".blocks (alias .of)" do
|
6
|
+
it "will always return an Array" do
|
7
|
+
assert_equal [], Unicode::Blocks.of("")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "will return all blocks that characters in the string belong to" do
|
11
|
+
assert_equal ["Basic Latin", "Cyrillic"], Unicode::Blocks.of("СC")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "will return all blocks in sorted order" do
|
15
|
+
assert_equal ["Basic Latin", "Cyrillic"], Unicode::Blocks.of("СA")
|
16
|
+
assert_equal ["Basic Latin", "Cyrillic"], Unicode::Blocks.of("AС")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "will call .block for every character" do
|
20
|
+
mocked_method = MiniTest::Mock.new
|
21
|
+
mocked_method.expect :call, "first block", ["С"]
|
22
|
+
mocked_method.expect :call, "second block", ["A"]
|
23
|
+
Unicode::Blocks.stub :block, mocked_method do
|
24
|
+
Unicode::Blocks.of("СA")
|
25
|
+
end
|
26
|
+
mocked_method.verify
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".block" do
|
31
|
+
it "will return block for that character" do
|
32
|
+
assert_equal "Specials", Unicode::Blocks.block("�")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "will return No_Block for characters not in any block" do
|
36
|
+
assert_equal "No_Block", Unicode::Blocks.block("\u{10c50}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".names" do
|
41
|
+
it "will return a list of all block names" do
|
42
|
+
assert_kind_of Array, Unicode::Blocks.names
|
43
|
+
assert_includes Unicode::Blocks.names, "Ancient Symbols"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/lib/unicode/blocks/constants"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "unicode-blocks"
|
7
|
+
gem.version = Unicode::Blocks::VERSION
|
8
|
+
gem.summary = "Return Unicode blocks of a string."
|
9
|
+
gem.description = "[Unicode version: #{Unicode::Blocks::UNICODE_VERSION}] Determine to which Unicode block characters belong to."
|
10
|
+
gem.authors = ["Jan Lelis"]
|
11
|
+
gem.email = ["mail@janlelis.de"]
|
12
|
+
gem.homepage = "https://github.com/janlelis/unicode-blocks"
|
13
|
+
gem.license = "MIT"
|
14
|
+
|
15
|
+
gem.files = Dir["{**/}{.*,*}"].select{ |path| File.file?(path) && path !~ /^pkg/ }
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.required_ruby_version = "~> 2.0"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unicode-blocks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Lelis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: "[Unicode version: 8.0.0] Determine to which Unicode block characters
|
14
|
+
belong to."
|
15
|
+
email:
|
16
|
+
- mail@janlelis.de
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".travis.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- MIT-LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- data/blocks.marshal.gz
|
30
|
+
- lib/unicode/blocks.rb
|
31
|
+
- lib/unicode/blocks/constants.rb
|
32
|
+
- lib/unicode/blocks/index.rb
|
33
|
+
- lib/unicode/blocks/string_ext.rb
|
34
|
+
- spec/unicode_blocks_spec.rb
|
35
|
+
- unicode-blocks.gemspec
|
36
|
+
homepage: https://github.com/janlelis/unicode-blocks
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.6.3
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Return Unicode blocks of a string.
|
60
|
+
test_files:
|
61
|
+
- spec/unicode_blocks_spec.rb
|
62
|
+
has_rdoc:
|