cbeta 1.3.3 → 1.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 251ea030c514e75aa21cee73df8e765357f52e44
4
- data.tar.gz: 4acc339dd5a48ac0f89e219b5d64042bfc58c3da
3
+ metadata.gz: adee183353751f8a74f171836a257f0259389791
4
+ data.tar.gz: 781dbd2f88fdb9f5358c01333215489623ed2461
5
5
  SHA512:
6
- metadata.gz: e5a9c75960a0fed07d3aa660acaa72258089b9c5e35693a1fba84b91a614ea4bf962482893fee3f3b5a4d8bfeb47eebc6cbec5105b90099d9d3864a5cd474fe0
7
- data.tar.gz: 2f90d55112deb33061f989eef400bb08cc6f12e141b1747c84da21f61be4ea1c72fc577c193dea22f69ea7858c0eda2cb471bb1154a2027450f7f7b256c38df7
6
+ metadata.gz: 59ce383bb2e3a054d8279abcc0f3e6fafc4b8c3f7850ddffdbb8ab7e25c0456922d75325881757e95d2554236bc2812a29394028edd09be29b4b5612c4b711fe
7
+ data.tar.gz: a37ab4e373efff9d964dbf0c1fd83b5225b114419e7adee793fa0fc0ca9d4df7b129b4342ed07e2a86a962cd2d149d3b0dd95c29b9a3074870635e5f2cd7e805
@@ -31,6 +31,11 @@ class CBETA
31
31
  doc
32
32
  end
33
33
 
34
+ # 傳入 缺字碼,傳回 Unicode PUA 字元
35
+ def self.pua(gid)
36
+ [0xf0000 + gid[2..-1].to_i].pack 'U'
37
+ end
38
+
34
39
  # 傳入 蘭札體 缺字碼,傳回 Unicode PUA 字元
35
40
  def self.ranjana_pua(gid)
36
41
  i = 0x10000 + gid[-4..-1].hex
@@ -6,6 +6,14 @@ class CBETA::Gaiji
6
6
  def initialize()
7
7
  fn = File.join(File.dirname(__FILE__), '../data/gaiji.json')
8
8
  @gaijis = JSON.parse(File.read(fn))
9
+
10
+ @zzs = {}
11
+ @gaijis.each do |k,v|
12
+ if v.key? 'zzs'
13
+ zzs = v['zzs']
14
+ @zzs[zzs] = k
15
+ end
16
+ end
9
17
  end
10
18
 
11
19
  # 取得缺字資訊
@@ -51,6 +59,13 @@ class CBETA::Gaiji
51
59
  File.write(output_json_filename, s)
52
60
  end
53
61
 
62
+ # 傳入 組字式,取得 PUA
63
+ def zzs2pua(zzs)
64
+ return nil unless @zzs.key? zzs
65
+ gid = @zzs[zzs]
66
+ CBETA.pua(gid)
67
+ end
68
+
54
69
  private
55
70
 
56
71
  def char_to_hash(char)
@@ -25,13 +25,17 @@ class CBETA::P5aToText
25
25
  # @param format [String] 輸出格式,例:'app'
26
26
  # @option opts [String] :format 輸出格式,例:'app',預設是 normal
27
27
  # @option opts [String] :encoding 輸出編碼,預設 'UTF-8'
28
+ # @option opts [String] :gaiji 缺字處理方式,預設 'default'
29
+ # * 'PUA': 缺字一律使用 Unicode PUA
30
+ # * 'default': 優先使用通用字
28
31
  def initialize(xml_root, output_root, opts={})
29
32
  @xml_root = xml_root
30
33
  @output_root = output_root
31
34
 
32
35
  @settings = {
33
36
  format: nil,
34
- encoding: 'UTF-8'
37
+ encoding: 'UTF-8',
38
+ gaiji: 'default'
35
39
  }
36
40
  @settings.merge!(opts)
37
41
 
@@ -192,6 +196,13 @@ class CBETA::P5aToText
192
196
  # else
193
197
  # Unicode PUA
194
198
  gid = e['ref'][1..-1]
199
+
200
+ if @settings[:gaiji] == 'PUA'
201
+ return CBETA.siddham_pua(gid) if gid.start_with?('SD') # 悉曇字
202
+ return CBETA.ranjana_pua(gid) if gid.start_with?('RJ') # 蘭札體
203
+ return CBETA.pua(gid)
204
+ end
205
+
195
206
  g = @gaijis[gid]
196
207
  abort "Line:#{__LINE__} 無缺字資料:#{gid}" if g.nil?
197
208
  zzs = g['zzs']
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: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Chou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2015-12-07 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