Class: CBETA::P5aChecker

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

Overview

檢查 CBETA XML P5a

Instance Method Summary collapse

Methods included from CbetaShare

#each_canon, #to_html

Constructor Details

#initialize(xml_root: nil, figures: nil, log: nil) ⇒ P5aChecker

Returns a new instance of P5aChecker.

Parameters:

  • xml_root (String) (defaults to: nil)

    來源 CBETA XML P5a 路徑

  • figures (String) (defaults to: nil)

    插圖 路徑 (可由 github.com/cbeta-git/CBR2X-figures 取得)

  • log (String) (defaults to: nil)

    Log file path



8
9
10
11
12
13
# File 'lib/cbeta/p5a_checker.rb', line 8

def initialize(xml_root: nil, figures: nil, log: nil)
  @gaijis = CBETA::Gaiji.new
  @xml_root = xml_root
  @figures = figures
  @log = log
end

Instance Method Details

#checkObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cbeta/p5a_checker.rb', line 15

def check
  @errors = ''
  @g_errors = {}
  puts "xml: #{@xml_root}"
  each_canon(@xml_root) do |c|
    @canon = c
    path = File.join(@xml_root, @canon)
    handle_canon(path)
  end

  @g_errors.keys.sort.each do |k|
    s = @g_errors[k].to_a.join(',')
    @errors << "#{k} 無缺字資料,出現於:#{s}\n"
  end
  
  if @errors.empty?
    puts "檢查完成,未發現錯誤。"
  elsif @log.nil?
    puts "\n發現錯誤:"
    puts @errors
  else
    File.write(@log, @errors)
    puts "\n發現錯誤,請查看 #{@log}"
  end
end