Class: CBETA
- Inherits:
-
Object
- Object
- CBETA
- Defined in:
- lib/cbeta.rb
Defined Under Namespace
Classes: BMToText, Gaiji, HTMLToText, P5aToEPUB, P5aToHTML, P5aToHTMLForEveryEdition, P5aToSimpleHTML, P5aToText, P5aValidator
Class Method Summary collapse
-
.linehead_to_s(linehead) ⇒ String
將行首資訊轉為引用格式.
-
.ranjana_pua(gid) ⇒ Object
傳入 蘭札體 缺字碼,傳回 Unicode PUA 字元.
-
.siddham_pua(gid) ⇒ Object
傳入 悉曇字 缺字碼,傳回 Unicode PUA 字元.
Instance Method Summary collapse
-
#get_canon_abbr(id) ⇒ String
取得藏經略名.
-
#get_canon_symbol(id) ⇒ String
取得藏經略符.
-
#get_category(book_id) ⇒ String
傳入經號,取得部類.
-
#initialize ⇒ CBETA
constructor
載入藏經資料.
Constructor Details
#initialize ⇒ CBETA
載入藏經資料
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cbeta.rb', line 37 def initialize() fn = File.join(File.dirname(__FILE__), 'data/canons.csv') text = File.read(fn) @canon_abbr = {} CSV.parse(text, :headers => true) do |row| next if row['abbreviation'].nil? next if row['abbreviation'].empty? @canon_abbr[row['id']] = row['abbreviation'] end fn = File.join(File.dirname(__FILE__), 'data/categories.json') s = File.read(fn) @categories = JSON.parse(s) end |
Class Method Details
.linehead_to_s(linehead) ⇒ String
將行首資訊轉為引用格式
17 18 19 20 21 22 |
# File 'lib/cbeta.rb', line 17 def self.linehead_to_s(linehead) linehead.match(/^([A-Z]\d+)n(.*)_p(\d+)([a-z]\d+)$/) { return "#{$1}, no. #{$2}, p. #{$3}, #{$4}" } nil end |
.ranjana_pua(gid) ⇒ Object
傳入 蘭札體 缺字碼,傳回 Unicode PUA 字元
25 26 27 28 |
# File 'lib/cbeta.rb', line 25 def self.ranjana_pua(gid) i = 0x10000 + gid[-4..-1].hex [i].pack("U") end |
.siddham_pua(gid) ⇒ Object
傳入 悉曇字 缺字碼,傳回 Unicode PUA 字元
31 32 33 34 |
# File 'lib/cbeta.rb', line 31 def self.siddham_pua(gid) i = 0xFA000 + gid[-4..-1].hex [i].pack("U") end |
Instance Method Details
#get_canon_abbr(id) ⇒ String
取得藏經略名
73 74 75 76 77 |
# File 'lib/cbeta.rb', line 73 def get_canon_abbr(id) r = get_canon_symbol(id) return nil if r.nil? r.sub(/^【(.*?)】$/, '\1') end |
#get_canon_symbol(id) ⇒ String
取得藏經略符
60 61 62 63 |
# File 'lib/cbeta.rb', line 60 def get_canon_symbol(id) return nil unless @canon_abbr.key? id @canon_abbr[id] end |
#get_category(book_id) ⇒ String
傳入經號,取得部類
86 87 88 |
# File 'lib/cbeta.rb', line 86 def get_category(book_id) @categories[book_id] end |