Class: Pdbook::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/pdbook/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, output, font = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf", options = {:page_size => "A4", :margin => 0.6.in, :font_size => 20, :spacing => 10, :compress => true}) ⇒ Converter

Returns a new instance of Converter.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pdbook/converter.rb', line 12

def initialize(input, output, font = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf", options = {:page_size => "A4", :margin => 0.6.in, :font_size => 20, :spacing => 10, :compress => true})
  @input = input
  @output = output
  @font = font
  @options = options
  @options[:page_size] = ENV["page_size"] if ENV["page_size"]
  @options[:margin] = (ENV["margin"].to_f * 1.in) if ENV["margin"]
  @options[:font_size] = ENV["font_size"].to_f if ENV["font_size"]
  @options[:spacing] = ENV["spacing"].to_f if ENV["spacing"]

  @pdb = Palm::PDB.new(input)
  @log = Logger.new($STDOUT)
end

Instance Method Details

#convert!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pdbook/converter.rb', line 26

def convert!
  data = @pdb.data
  Prawn::Document.generate @output, @options do |doc|
    doc.font @font
    toc = data.shift.data
    content = data

    # render cover & toc
    render_toc(doc, toc)
  
    # render content
    doc.text_options.update(:wrap => :character, :size => @options[:font_size], :spacing => @options[:spacing])            
    content.each do |record|
      render_content(doc, record.data)
    end
  end
end