Class: CBETA::P5aToSimpleHTML

Inherits:
Object
  • Object
show all
Includes:
CbetaShare
Defined in:
lib/cbeta/p5a_to_simple_html.rb

Overview

Convert CBETA XML P5a to simple HTML

  • HTML 中除了純文字之外,只有行號標記

  • 每一卷、每個校勘版本都產生一個檔案

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

Examples:

for convert 大正藏第一冊:


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

Instance Method Summary collapse

Methods included from CbetaShare

#to_html

Constructor Details

#initialize(xml_root, output_root, gaiji_base, opts = {}) ⇒ P5aToSimpleHTML

Returns a new instance of P5aToSimpleHTML.

Parameters:

  • xml_root (String)

    來源 CBETA XML P5a 路徑

  • output_root (String)

    輸出 Text 路徑



28
29
30
31
32
33
34
35
# File 'lib/cbeta/p5a_to_simple_html.rb', line 28

def initialize(xml_root, output_root, gaiji_base, opts={})
  @xml_root = xml_root
  @output_root = output_root
  @cbeta = CBETA.new
  @gaijis = CBETA::Gaiji.new(gaiji_base)
  @config = { multi_edition: false }
  @config.merge!(opts)
end

Instance Method Details

#convert(target = nil) ⇒ Object

將 CBETA XML P5a 轉為 Simple HTML

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

Examples:

for convert 大正藏第一冊:


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

for convert 大正藏全部:


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

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


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


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cbeta/p5a_to_simple_html.rb', line 55

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

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