cbeta 3.2.1 → 3.3.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
  SHA256:
3
- metadata.gz: 5d32b2ace3526aa8492fcfb42bbbebf08edfa1a1df1d3ef5aecc8e409e7423a9
4
- data.tar.gz: 67bb568adb4710f114216161e16a6c7c5e0a0c34af6b770a42fc1e26143a3b03
3
+ metadata.gz: d6371fac001d191b3245ba02d1b3287cedfe46213bea091d9259d9d24c2454b7
4
+ data.tar.gz: f71e61e1598462fd02fed5eb8e1c0111ee259d1b3bb85424ce869a9f0ea0dad8
5
5
  SHA512:
6
- metadata.gz: 71ade7189b3f3bf90f9436e1d756c88f72164285972d7cab8cb81bb2ed27d2c13a048e2909cfb58f8250288e5d31bee888acedf6cf4ea225db5e7ea5605db575
7
- data.tar.gz: f84625e849635021b7ba2c10b7b54725830bce6786eb40fe8b3696b8b732274ec89cbbb4fbedb9e494be88f221e7252c23d90fe83fe8e8b81edc8189bf9969f0
6
+ metadata.gz: fcc4e69ae85ef617ab214e489842d6c82a4c61fa7326c5f3d9ada35f49e71b602bb4f7c4153aeb9e3aa5c978a52ac19cc926842ea2535e6518b4c518e80f274a
7
+ data.tar.gz: 837dc5642b1285cf602a66572908d0ac4b3b3a32e7a509ee1c19337ea5f9363b3cbf9b1d59cab65565f45dd39808eff511383521c633ecc08fe480c9c360a6bb
data/lib/cbeta/gaiji.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'json'
2
+ require 'unihan2'
2
3
 
3
4
  # 存取 CBETA 缺字資料庫
4
5
  class CBETA::Gaiji
5
6
 
6
7
  # 載入 CBETA 缺字資料庫
7
8
  def initialize
9
+ @us = CBETA::UnicodeService.new
8
10
  folder = File.join(File.dirname(__FILE__), '../data')
9
11
  fn = File.join(folder, 'cbeta_gaiji.json')
10
12
  @gaijis = JSON.parse(File.read(fn))
@@ -73,9 +75,12 @@ class CBETA::Gaiji
73
75
 
74
76
  if gid.start_with? 'CB'
75
77
  cb_priority.each do |k|
76
- if k == 'PUA'
78
+ case k
79
+ when 'PUA'
77
80
  return CBETA.pua(gid)
78
- elsif g.key? k
81
+ when 'uni_char', 'norm_uni_char'
82
+ return g[k] if @us.level2?(g[k])
83
+ else
79
84
  return g[k] unless g[k].empty?
80
85
  end
81
86
  end
@@ -0,0 +1,19 @@
1
+ class CBETA::UnicodeService
2
+ def initialize
3
+ @u2 = Unihan2.new
4
+ end
5
+
6
+ def level1?(code)
7
+ return false if code.nil?
8
+ # Unicode 3.0 以內 在 mobile 可以正確顯示
9
+ v = @u2.ver(code)
10
+ raise "Unihan2.ver 回傳 nil, code: #{code}" if v.nil?
11
+ v <= 3
12
+ end
13
+
14
+ def level2?(code)
15
+ return false if code.nil?
16
+ # Unicode 10 以內 在 desktop 有字型可以顯示
17
+ @u2.ver(code) <= 10
18
+ end
19
+ end
data/lib/cbeta.rb CHANGED
@@ -234,4 +234,5 @@ require 'cbeta/p5a_to_simple_html'
234
234
  require 'cbeta/p5a_to_text'
235
235
  require 'cbeta/p5a_validator'
236
236
  require 'cbeta/html_to_text'
237
+ require 'cbeta/unicode_service'
237
238
  require 'cbeta/xml_document'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbeta
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Chou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem for use Chinese Buddhist Text resources made by CBETA (http://www.cbeta.org).
14
14
  email: zhoubx@gmail.com
@@ -31,6 +31,7 @@ files:
31
31
  - lib/cbeta/p5a_to_simple_html.rb
32
32
  - lib/cbeta/p5a_to_text.rb
33
33
  - lib/cbeta/p5a_validator.rb
34
+ - lib/cbeta/unicode_service.rb
34
35
  - lib/cbeta/xml_document.rb
35
36
  - lib/data/canons.csv
36
37
  - lib/data/categories.json