Class: CBETA::P5aValidator

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

Overview

檢查 xml 是否符合 CBETA xml-p5a 編輯體例

Examples:

require 'cbeta'

RNG = '/Users/ray/Documents/Projects/cbeta/schema/cbeta-p5a.rng'
XML = '/Users/ray/Dropbox/DILA-CBETA/目次跨卷/xml/完成'

v = CBETA::P5aValidator.new(RNG)
s = v.check(XML)

if s.empty?
  puts "檢查成功,未發現錯誤。"
else
  File.write('check.log', s)
  puts "發現錯誤,請查看 check.log。"
end

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ P5aValidator

Returns a new instance of P5aValidator.

Parameters:

  • schema (String)

    RelaxNG schema file path



26
27
28
# File 'lib/cbeta/p5a_validator.rb', line 26

def initialize(schema)
  @schema = schema
end

Instance Method Details

#check(xml_path) ⇒ String

Returns 沒有錯誤的話,傳回空字串,否則傳回錯誤訊息。.

Parameters:

  • xml_root (String)

    來源 CBETA XML P5a 路徑

Returns:

  • (String)

    沒有錯誤的話,傳回空字串,否則傳回錯誤訊息。



32
33
34
35
36
37
38
39
40
# File 'lib/cbeta/p5a_validator.rb', line 32

def check(xml_path)
  r = ''
  if Dir.exist? xml_path
    r = check_folder xml_path
  else
    r = check_file xml_path
  end
  r
end