Class: CBETA::HTMLToPDF
- Inherits:
-
Object
- Object
- CBETA::HTMLToPDF
- Defined in:
- lib/cbeta/html_to_pdf.rb
Instance Method Summary collapse
-
#convert(target = nil) ⇒ Object
Convert CBETA HTML to PDF.
- #convert_collection(c) ⇒ Object
- #convert_file(html_fn, pdf_fn) ⇒ Object
-
#initialize(input, output, converter) ⇒ HTMLToPDF
constructor
A new instance of HTMLToPDF.
Constructor Details
#initialize(input, output, converter) ⇒ HTMLToPDF
Returns a new instance of HTMLToPDF.
12 13 14 15 16 |
# File 'lib/cbeta/html_to_pdf.rb', line 12 def initialize(input, output, converter) @input = input @output = output @converter = converter end |
Instance Method Details
#convert(target = nil) ⇒ Object
Convert CBETA HTML to PDF
T 是大正藏的 ID, CBETA 的藏經 ID 系統請參考: www.cbeta.org/format/id.php
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cbeta/html_to_pdf.rb', line 36 def convert(target=nil) return convert_all if target.nil? arg = target.upcase if arg.size <= 2 convert_collection(arg) else if arg.include? '..' arg.match(/^([^\.]+?)\.\.([^\.]+)$/) { convert_vols($1, $2) } else convert_vol(arg) end end end |
#convert_collection(c) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cbeta/html_to_pdf.rb', line 53 def convert_collection(c) @canon = c puts 'convert_collection ' + c output_folder = File.join(@output, @canon) FileUtils.mkdir_p(output_folder) unless Dir.exist? output_folder folder = File.join(@input, @canon) Dir.foreach(folder) { |f| next if f.start_with? '.' src = File.join(folder, f, 'main.htm') dest = File.join(output_folder, "#{f}.pdf") convert_file(src, dest) } end |
#convert_file(html_fn, pdf_fn) ⇒ Object
69 70 71 72 73 |
# File 'lib/cbeta/html_to_pdf.rb', line 69 def convert_file(html_fn, pdf_fn) puts "convert file: #{html_fn} to #{pdf_fn}" cmd = @converter % { in: html_fn, out: pdf_fn} `#{cmd}` end |