cbeta 4.1.0 → 4.3.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 +0 -0
- data/lib/cbeta/gaiji.rb +39 -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: d87e5abf202e1a364780efea5d54761eef5a59c19ff68b17e051fdd119f0baa5
|
|
4
|
+
data.tar.gz: c1720705f1a5beabb8267568baab667973e722321a41c2b5139063f203289f04
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9cf1756da5884ecb2414981f99fdabede3d7bc511b9002d62d5f9581bbe9232b037409dc6c361771eded7a5edb1cb3e720ce91cc0ceddf6060a50ea274e679fa
|
|
7
|
+
data.tar.gz: f8854526080b42a3e53e52f8b775afeaed21cd2a9a66c35947a71c0b2a7551d6860e03c1cca92f4e19f43b20c617ebf80a1a54d20750cdfe42d7c9d2fdcd90b1
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/cbeta/gaiji.rb
CHANGED
|
@@ -1,19 +1,48 @@
|
|
|
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
|
+
|
|
8
|
+
# 內建缺字資料的期別(CBETA 釋出版本)
|
|
9
|
+
DATA_VERSION = '2026.R2'
|
|
10
|
+
|
|
11
|
+
# 缺字資料的期別。使用內建資料時為 {DATA_VERSION};
|
|
12
|
+
# 使用外部資料時為呼叫者傳入的 data_version,未傳入則為 nil。
|
|
13
|
+
#
|
|
14
|
+
# @return [String, nil]
|
|
15
|
+
attr_reader :data_version
|
|
16
|
+
|
|
7
17
|
# 載入 CBETA 缺字資料庫
|
|
8
|
-
|
|
18
|
+
#
|
|
19
|
+
# 預設使用 gem 內建的缺字資料。也可以傳入外部檔案路徑,自行決定要使用哪一份資料,
|
|
20
|
+
# 例如 https://github.com/cbeta-org/cbeta_gaiji 某個版本的 cbeta_gaiji.json,
|
|
21
|
+
# 讓缺字資料版本與 gem 版本脫鉤。外部檔案必須與 cbeta_gaiji repo 的 JSON 格式相同。
|
|
22
|
+
#
|
|
23
|
+
# @param gaiji_path [String, nil] CB 缺字資料(cbeta_gaiji.json)路徑,nil 表示使用內建資料
|
|
24
|
+
# @param sanskrit_path [String, nil] 悉曇、蘭札資料(cbeta_sanskrit.json)路徑,nil 表示使用內建資料
|
|
25
|
+
# @param data_version [String, nil] 外部缺字資料的期別,供 {#data_version} 回傳;
|
|
26
|
+
# gaiji_path、sanskrit_path 都未指定時忽略此參數,一律為 {DATA_VERSION}
|
|
27
|
+
#
|
|
28
|
+
# @example 使用內建資料
|
|
29
|
+
# g = CBETA::Gaiji.new
|
|
30
|
+
#
|
|
31
|
+
# @example 使用外部資料
|
|
32
|
+
# g = CBETA::Gaiji.new(
|
|
33
|
+
# gaiji_path: '/path/to/cbeta_gaiji/cbeta_gaiji.json',
|
|
34
|
+
# sanskrit_path: '/path/to/cbeta_gaiji/cbeta_sanskrit.json',
|
|
35
|
+
# data_version: '2026.R3'
|
|
36
|
+
# )
|
|
37
|
+
def initialize(gaiji_path: nil, sanskrit_path: nil, data_version: nil)
|
|
9
38
|
@us = CBETA::UnicodeService.new
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@gaijis.merge!(
|
|
39
|
+
builtin = gaiji_path.nil? && sanskrit_path.nil?
|
|
40
|
+
@data_version = builtin ? DATA_VERSION : data_version
|
|
41
|
+
gaiji_path ||= File.join(DATA_FOLDER, 'cbeta_gaiji.json')
|
|
42
|
+
sanskrit_path ||= File.join(DATA_FOLDER, 'cbeta_sanskrit.json')
|
|
43
|
+
|
|
44
|
+
@gaijis = JSON.parse(File.read(gaiji_path))
|
|
45
|
+
@gaijis.merge!(JSON.parse(File.read(sanskrit_path)))
|
|
17
46
|
|
|
18
47
|
@zzs = {}
|
|
19
48
|
@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.3.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
|