Class: CBETA::P5aToHTML

Inherits:
Object
  • Object
show all
Defined in:
lib/cbeta/p5a_to_html.rb

Overview

Convert CBETA XML P5a to HTML

CBETA XML P5a 可由此取得: github.com/cbeta-git/xml-p5a

轉檔規則請參考: wiki.ddbc.edu.tw/pages/CBETA_XML_P5a_轉_HTML

Instance Method Summary collapse

Constructor Details

#initialize(xml_root, out_root) ⇒ P5aToHTML

Returns a new instance of P5aToHTML.

Parameters:

  • xml_root (String)

    來源 CBETA XML P5a 路徑

  • out_root (String)

    輸出 HTML 路徑



24
25
26
27
28
29
# File 'lib/cbeta/p5a_to_html.rb', line 24

def initialize(xml_root, out_root)
  @xml_root = xml_root
  @out_root = out_root
  @cbeta = CBETA.new
  @gaijis = CBETA::Gaiji.new
end

Instance Method Details

#convert(target = nil) ⇒ Object

將 CBETA XML P5a 轉為 HTML

T 是大正藏的 ID, CBETA 的藏經 ID 系統請參考: www.cbeta.org/format/id.php

Examples:

for convert 大正藏第一冊:


x2h = CBETA::P5aToHTML.new('/PATH/TO/CBETA/XML/P5a', '/OUTPUT/FOLDER')
x2h.convert('T01')

for convert 大正藏全部:


x2h = CBETA::P5aToHTML.new('/PATH/TO/CBETA/XML/P5a', '/OUTPUT/FOLDER')
x2h.convert('T')

for convert 大正藏第五冊至第七冊:


x2h = CBETA::P5aToHTML.new('/PATH/TO/CBETA/XML/P5a', '/OUTPUT/FOLDER')
x2h.convert('T05..T07')


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cbeta/p5a_to_html.rb', line 49

def convert(target=nil)
  return convert_all if target.nil?

  arg = target.upcase
  if arg.size == 1
    handle_collection(arg)
  else
    if arg.include? '..'
      arg.match(/^([^\.]+?)\.\.([^\.]+)$/) {
        handle_vols($1, $2)
      }
    else
      handle_vol(arg)
    end
  end
end