cbeta 4.1.0 → 4.2.0
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
- checksums.yaml.gz.sig +4 -2
- data/lib/cbeta/gaiji.rb +25 -10
- data/lib/cbeta/unicode_service.rb +19 -9
- data.tar.gz.sig +0 -0
- metadata +1 -21
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e86b3e6256a56e239bd95259c3e040ce05563740aa7a53ae387bbdace4bae2e1
|
|
4
|
+
data.tar.gz: d72162f4ea8d9c0650d748b3593c3ddabe259dd295438d7aed7a474b93bfe5bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e75dbd36ac5ececb236bac18deff9692055188456cc42afe69a99218948013943229e5f3679272491c9ff6baaac0f06654a2f1ff9965df0bb2dbff3b9d048d45
|
|
7
|
+
data.tar.gz: 644492039267b108f6d35fdf97fb937bbff1ce592d2090169171a89d94aa235e59068eb1dc92fb6ca3c10fd1afa4c0c6a8e48c87c29fff9b49fe05431ecdf4e1
|
checksums.yaml.gz.sig
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
U<�:�[a=�D=��!�Ft/R����G9�}$(ACTc�ݪ }���0c��,����U�
|
|
2
|
+
���x�j�b}��>/8 Ԫ�)Y�5�nay����c���I���YC����&&�y���X���^ScL��v����E�N`�i�9�Ƨ��jjl1��'}ڌT�7�&��:�e �u��
|
|
3
|
+
Y�`�M�gW��f�y�<E��TsP���Q�e�>J���43�`Z����Nl�Ubb��;�JS
|
|
4
|
+
����nU�&�к��Wó�/�3@Ӕ�:
|
data/lib/cbeta/gaiji.rb
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
-
require 'unihan2'
|
|
3
2
|
|
|
4
3
|
# 存取 CBETA 缺字資料庫
|
|
5
4
|
class CBETA::Gaiji
|
|
6
|
-
|
|
5
|
+
# 內建缺字資料所在的資料夾
|
|
6
|
+
DATA_FOLDER = File.expand_path('../data', __dir__)
|
|
7
|
+
|
|
7
8
|
# 載入 CBETA 缺字資料庫
|
|
8
|
-
|
|
9
|
+
#
|
|
10
|
+
# 預設使用 gem 內建的缺字資料。也可以傳入外部檔案路徑,自行決定要使用哪一份資料,
|
|
11
|
+
# 例如 https://github.com/cbeta-org/cbeta_gaiji 某個版本的 cbeta_gaiji.json,
|
|
12
|
+
# 讓缺字資料版本與 gem 版本脫鉤。外部檔案必須與 cbeta_gaiji repo 的 JSON 格式相同。
|
|
13
|
+
#
|
|
14
|
+
# @param gaiji_path [String, nil] CB 缺字資料(cbeta_gaiji.json)路徑,nil 表示使用內建資料
|
|
15
|
+
# @param sanskrit_path [String, nil] 悉曇、蘭札資料(cbeta_sanskrit.json)路徑,nil 表示使用內建資料
|
|
16
|
+
#
|
|
17
|
+
# @example 使用內建資料
|
|
18
|
+
# g = CBETA::Gaiji.new
|
|
19
|
+
#
|
|
20
|
+
# @example 使用外部資料
|
|
21
|
+
# g = CBETA::Gaiji.new(
|
|
22
|
+
# gaiji_path: '/path/to/cbeta_gaiji/cbeta_gaiji.json',
|
|
23
|
+
# sanskrit_path: '/path/to/cbeta_gaiji/cbeta_sanskrit.json'
|
|
24
|
+
# )
|
|
25
|
+
def initialize(gaiji_path: nil, sanskrit_path: nil)
|
|
9
26
|
@us = CBETA::UnicodeService.new
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
h = JSON.parse(File.read(fn))
|
|
16
|
-
@gaijis.merge!(h)
|
|
27
|
+
gaiji_path ||= File.join(DATA_FOLDER, 'cbeta_gaiji.json')
|
|
28
|
+
sanskrit_path ||= File.join(DATA_FOLDER, 'cbeta_sanskrit.json')
|
|
29
|
+
|
|
30
|
+
@gaijis = JSON.parse(File.read(gaiji_path))
|
|
31
|
+
@gaijis.merge!(JSON.parse(File.read(sanskrit_path)))
|
|
17
32
|
|
|
18
33
|
@zzs = {}
|
|
19
34
|
@uni2cb = {}
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
# 判斷字元收錄於哪一版 Unicode
|
|
2
|
+
#
|
|
3
|
+
# 使用 Ruby 內建 regexp 的 Unicode Age 屬性(\p{Age=...})判斷。
|
|
4
|
+
# Age 屬性一經指定就不會變動,所以結果不受 Ruby 版本影響。
|
|
1
5
|
class CBETA::UnicodeService
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
# Unicode 3.0 以內
|
|
7
|
+
LEVEL1 = /\A\p{Age=3.0}+\z/
|
|
8
|
+
|
|
9
|
+
# Unicode 10.0 以內
|
|
10
|
+
LEVEL2 = /\A\p{Age=10.0}+\z/
|
|
5
11
|
|
|
12
|
+
# Unicode 3.0 以內 在 mobile 可以正確顯示
|
|
13
|
+
#
|
|
14
|
+
# @param code [String] 字元
|
|
15
|
+
# @return [Boolean]
|
|
6
16
|
def level1?(code)
|
|
7
17
|
return false if code.nil?
|
|
8
|
-
|
|
9
|
-
v = @u2.ver(code)
|
|
10
|
-
raise "Unihan2.ver 回傳 nil, code: #{code}" if v.nil?
|
|
11
|
-
v <= 3
|
|
18
|
+
LEVEL1.match?(code)
|
|
12
19
|
end
|
|
13
20
|
|
|
21
|
+
# Unicode 10 以內 在 desktop 有字型可以顯示
|
|
22
|
+
#
|
|
23
|
+
# @param code [String] 字元
|
|
24
|
+
# @return [Boolean]
|
|
14
25
|
def level2?(code)
|
|
15
26
|
return false if code.nil?
|
|
16
|
-
|
|
17
|
-
@u2.ver(code) <= 10
|
|
27
|
+
LEVEL2.match?(code)
|
|
18
28
|
end
|
|
19
29
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cbeta
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ray Chou
|
|
@@ -36,26 +36,6 @@ cert_chain:
|
|
|
36
36
|
-----END CERTIFICATE-----
|
|
37
37
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
38
38
|
dependencies:
|
|
39
|
-
- !ruby/object:Gem::Dependency
|
|
40
|
-
name: unihan2
|
|
41
|
-
requirement: !ruby/object:Gem::Requirement
|
|
42
|
-
requirements:
|
|
43
|
-
- - "~>"
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
version: '1.2'
|
|
46
|
-
- - ">="
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: 1.2.0
|
|
49
|
-
type: :runtime
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - "~>"
|
|
54
|
-
- !ruby/object:Gem::Version
|
|
55
|
-
version: '1.2'
|
|
56
|
-
- - ">="
|
|
57
|
-
- !ruby/object:Gem::Version
|
|
58
|
-
version: 1.2.0
|
|
59
39
|
- !ruby/object:Gem::Dependency
|
|
60
40
|
name: nokogiri
|
|
61
41
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
|
Binary file
|