Class: CBETA::Gaiji
- Inherits:
-
Object
- Object
- CBETA::Gaiji
- Defined in:
- lib/cbeta/gaiji.rb
Overview
存取 CBETA 缺字資料庫
Instance Method Summary collapse
-
#[](cb) ⇒ Hash{String => Strin, Array<String>}?
取得缺字資訊.
-
#initialize(gaiji_base) ⇒ Gaiji
constructor
載入 CBETA 缺字資料庫 gaiji_base clone from github.com/cbeta-org/cbeta_gaiji.
-
#key?(cb) ⇒ Boolean
檢查某個缺字碼是否存在.
- #unicode_to_cb(unicode_char) ⇒ Object
-
#zhuyin(cb) ⇒ Array<String>
傳入缺字 CB 碼,傳回注音 array.
-
#zzs2pua(zzs) ⇒ Object
傳入 組字式,取得 PUA.
Constructor Details
#initialize(gaiji_base) ⇒ Gaiji
載入 CBETA 缺字資料庫gaiji_base clone from github.com/cbeta-org/cbeta_gaiji
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cbeta/gaiji.rb', line 7 def initialize(gaiji_base) fn = File.join(gaiji_base, 'cbeta_gaiji.json') @gaijis = JSON.parse(File.read(fn)) fn = File.join(gaiji_base, 'cbeta_sanskrit.json') h = JSON.parse(File.read(fn)) @gaijis.merge!(h) @zzs = {} @uni2cb = {} @gaijis.each do |k,v| if v.key? 'composition' zzs = v['composition'] @zzs[zzs] = k end if v.key? 'uni_char' c = v['uni_char'] @uni2cb[c] = k end end end |
Instance Method Details
#[](cb) ⇒ Hash{String => Strin, Array<String>}?
取得缺字資訊
Return:
{
"composition": "[得-彳]",
"unicode": "3775",
"uni_char": "㝵",
"zhuyin": [ "ㄉㄜˊ", "ㄞˋ" ]
}
47 48 49 |
# File 'lib/cbeta/gaiji.rb', line 47 def [](cb) @gaijis[cb] end |
#key?(cb) ⇒ Boolean
檢查某個缺字碼是否存在
52 53 54 |
# File 'lib/cbeta/gaiji.rb', line 52 def key?(cb) @gaijis.key? cb end |
#unicode_to_cb(unicode_char) ⇒ Object
56 57 58 |
# File 'lib/cbeta/gaiji.rb', line 56 def unicode_to_cb(unicode_char) @uni2cb[unicode_char] end |
#zhuyin(cb) ⇒ Array<String>
傳入缺字 CB 碼,傳回注音 array
資料來源:CBETA 於 2015.5.15 提供的 MS Access 缺字資料庫
70 71 72 73 |
# File 'lib/cbeta/gaiji.rb', line 70 def (cb) return nil unless @gaijis.key? cb @gaijis[cb]['zhuyin'] end |