cbeta 1.1.15 → 1.1.16
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
- data/lib/cbeta.rb +111 -0
- data/lib/cbeta/p5a_to_epub.rb +6 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96caf201945a8e525a455312cea612b569d13481
|
4
|
+
data.tar.gz: d5136a4f769b9ed10f23e78d65e96ba8ba781651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6bca7ac8a6f10024275360d7e15cc7b7bc16f81ff0c304cf3e24edff67e177c43990fea1b363f0976f9faa1aeb14c500c7582be9a596af7ef98a7792430d4d4
|
7
|
+
data.tar.gz: e2361d5614e1e6861aa27d9f38eb86543ef21accc59f777fefb0faad3a921aa6afe04e25c44cb5bf513e94b7960393f940334f7e3626d45e095bd818fe269511
|
data/lib/cbeta.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Ruby bools for access resources produced by CBETA
|
2
|
+
# (Chinese Buddhist Electronic Text Association, http://www.cbeta.org)
|
3
|
+
#
|
4
|
+
# 存取 CBETA 資源的 Ruby 工具
|
5
|
+
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
class CBETA
|
9
|
+
# 將行首資訊轉為引用格式
|
10
|
+
#
|
11
|
+
# @param linehead [String] 行首資訊, 例如:T85n2838_p1291a03
|
12
|
+
# @return [String] 引用格式的出處資訊,例如:T85, no. 2838, p. 1291, a03
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# CBETA.linehead_to_s('T85n2838_p1291a03')
|
16
|
+
# # return "T85, no. 2838, p. 1291, a03"
|
17
|
+
def self.linehead_to_s(linehead)
|
18
|
+
linehead.match(/^([A-Z]\d+)n(.*)_p(\d+)([a-z]\d+)$/) {
|
19
|
+
return "#{$1}, no. #{$2}, p. #{$3}, #{$4}"
|
20
|
+
}
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# 傳入 蘭札體 缺字碼,傳回 Unicode PUA 字元
|
25
|
+
def self.ranjana_pua(gid)
|
26
|
+
i = 0x10000 + gid[-4..-1].hex
|
27
|
+
[i].pack("U")
|
28
|
+
end
|
29
|
+
|
30
|
+
# 傳入 悉曇字 缺字碼,傳回 Unicode PUA 字元
|
31
|
+
def self.siddham_pua(gid)
|
32
|
+
i = 0xFA000 + gid[-4..-1].hex
|
33
|
+
[i].pack("U")
|
34
|
+
end
|
35
|
+
|
36
|
+
# 載入藏經資料
|
37
|
+
def initialize()
|
38
|
+
fn = File.join(File.dirname(__FILE__), 'data/canons.csv')
|
39
|
+
text = File.read(fn)
|
40
|
+
@canon_abbr = {}
|
41
|
+
@canon_nickname = {}
|
42
|
+
CSV.parse(text, :headers => true) do |row|
|
43
|
+
id = row['id']
|
44
|
+
unless row['nickname'].nil?
|
45
|
+
@canon_nickname[id] = row['nickname']
|
46
|
+
end
|
47
|
+
next if row['abbreviation'].nil?
|
48
|
+
next if row['abbreviation'].empty?
|
49
|
+
@canon_abbr[id] = row['abbreviation']
|
50
|
+
end
|
51
|
+
|
52
|
+
fn = File.join(File.dirname(__FILE__), 'data/categories.json')
|
53
|
+
s = File.read(fn)
|
54
|
+
@categories = JSON.parse(s)
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param id [String] 藏經 ID, 例如大正藏的 ID 是 "T"
|
58
|
+
# @return [String] 藏經短名,例如 "大正藏"
|
59
|
+
def get_canon_nickname(id)
|
60
|
+
return nil unless @canon_nickname.key? id
|
61
|
+
@canon_nickname[id]
|
62
|
+
end
|
63
|
+
|
64
|
+
# 取得藏經略符
|
65
|
+
#
|
66
|
+
# @param id [String] 藏經 ID, 例如大正藏的 ID 是 "T"
|
67
|
+
# @return [String] 藏經略符,例如 "【大】"
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# cbeta = CBETA.new
|
71
|
+
# cbeta.get_canon_symbol('T') # return "【大】"
|
72
|
+
def get_canon_symbol(id)
|
73
|
+
return nil unless @canon_abbr.key? id
|
74
|
+
@canon_abbr[id]
|
75
|
+
end
|
76
|
+
|
77
|
+
# 取得藏經略名
|
78
|
+
#
|
79
|
+
# @param id [String] 藏經 ID, 例如大正藏的 ID 是 "T"
|
80
|
+
# @return [String] 藏經短名,例如 "大"
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# cbeta = CBETA.new
|
84
|
+
# cbeta.get_canon_abbr('T') # return "大"
|
85
|
+
def get_canon_abbr(id)
|
86
|
+
r = get_canon_symbol(id)
|
87
|
+
return nil if r.nil?
|
88
|
+
r.sub(/^【(.*?)】$/, '\1')
|
89
|
+
end
|
90
|
+
|
91
|
+
# 傳入經號,取得部類
|
92
|
+
# @param book_id [String] Book ID (經號), ex. "T0220"
|
93
|
+
# @return [String] 部類名稱,例如 "阿含部類"
|
94
|
+
#
|
95
|
+
# @example
|
96
|
+
# cbeta = CBETA.new
|
97
|
+
# cbeta.get_category('T0220') # return '般若部類'
|
98
|
+
def get_category(book_id)
|
99
|
+
@categories[book_id]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
require 'cbeta/gaiji'
|
104
|
+
require 'cbeta/bm_to_text'
|
105
|
+
require 'cbeta/p5a_to_epub'
|
106
|
+
require 'cbeta/p5a_to_html'
|
107
|
+
require 'cbeta/p5a_to_html_for_every_edition'
|
108
|
+
require 'cbeta/p5a_to_simple_html'
|
109
|
+
require 'cbeta/p5a_to_text'
|
110
|
+
require 'cbeta/p5a_validator'
|
111
|
+
require 'cbeta/html_to_text'
|
data/lib/cbeta/p5a_to_epub.rb
CHANGED
@@ -90,6 +90,7 @@ class CBETA::P5aToEPUB
|
|
90
90
|
# c = CBETA::P5aToEPUB.new(TEMP, IMG)
|
91
91
|
# c.convert_folder('/Users/ray/Documents/Projects/D道安/xml-p5a/DA', '/temp/cbeta-epub/DA')
|
92
92
|
def convert_folder(input_folder, output_folder)
|
93
|
+
puts "convert folder: #{input_folder} to #{output_folder}"
|
93
94
|
@todo = {}
|
94
95
|
|
95
96
|
# 先檢視整個資料夾,哪些是要多檔合一
|
@@ -168,12 +169,13 @@ class CBETA::P5aToEPUB
|
|
168
169
|
|
169
170
|
title = @title
|
170
171
|
book_id = @book_id
|
172
|
+
creator = @author
|
171
173
|
builder = GEPUB::Builder.new {
|
172
174
|
language 'zh-TW'
|
173
175
|
unique_identifier "http://www.cbeta.org/#{book_id}", 'BookID', 'URL'
|
174
176
|
title title
|
175
177
|
|
176
|
-
creator
|
178
|
+
creator creator
|
177
179
|
|
178
180
|
contributors 'DILA'
|
179
181
|
|
@@ -752,7 +754,7 @@ eos
|
|
752
754
|
@current_nav = [@nav_root_ol]
|
753
755
|
|
754
756
|
if @settings[:front_page_title]
|
755
|
-
@nav_root_ol.add_child("<li><a href='
|
757
|
+
@nav_root_ol.add_child("<li><a href='front.xhtml'>編輯說明</a></li>")
|
756
758
|
end
|
757
759
|
|
758
760
|
li = @nav_root_ol.add_child("<li><a href='#'>章節目次</a></li>").first
|
@@ -807,6 +809,8 @@ eos
|
|
807
809
|
@title = traverse(e, 'txt')
|
808
810
|
@title = @title.split()[-1]
|
809
811
|
|
812
|
+
@author = doc.at_xpath("//titleStmt/author").text
|
813
|
+
|
810
814
|
read_mod_notes(doc)
|
811
815
|
|
812
816
|
root = doc.root()
|
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.1.
|
4
|
+
version: 1.1.16
|
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-
|
11
|
+
date: 2015-11-03 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
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/cbeta.rb
|
19
20
|
- lib/cbeta/bm_to_text.rb
|
20
21
|
- lib/cbeta/gaiji.rb
|
21
22
|
- lib/cbeta/html_to_text.rb
|