Class: CBETA::P5aToText

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

Overview

Convert CBETA XML P5a to Text

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

Examples:

for convert 大正藏第一冊 in app format:


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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of P5aToText.

Parameters:

  • xml_root (String)

    來源 CBETA XML P5a 路徑

  • output_root (String)

    輸出 Text 路徑

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :format (String)

    輸出格式,例:‘app’,預設是 normal

  • :encoding (String)

    輸出編碼,預設 ‘UTF-8’

  • :gaiji (String)

    缺字處理方式,預設 ‘default’

  • :inline_note (String)

    是否呈現夾註,預設為 true

    • ‘PUA’: 缺字一律使用 Unicode PUA

    • ‘default’: 優先使用通用字



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cbeta/p5a_to_text.rb', line 31

def initialize(xml_root, output_root, opts={})
  @xml_root = xml_root
  @output_root = output_root
  
  @settings = {
    format: nil,
    encoding: 'UTF-8',
    gaiji: 'default',
    inline_note: true
  }
  @settings.merge!(opts)
  
  @cbeta = CBETA.new
  @gaijis = CBETA::Gaiji.new
end

Instance Method Details

#convert(target = nil) ⇒ Object

將 CBETA XML P5a 轉為 Text

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

Examples:

for convert all:


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

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')


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cbeta/p5a_to_text.rb', line 70

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

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