Module: Crucigrama::Crossword::PdfPrintable

Defined in:
lib/crucigrama/crossword/pdf_printable.rb

Overview

This module provides a to_pdf method that allows the printing of a crossword in PDF format

Constant Summary collapse

PDF_CELL_SIZE =
20

Instance Method Summary collapse

Instance Method Details

#to_pdf(file, options = {}) ⇒ Object

Prints the crossword on the given file in PDF format

Options Hash (options):

  • :include_solution (Boolean)

    whether or not to print a reduced and inverted solved crossword next to the actual one (false by default)



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

def to_pdf(file, options = {})
  drawing_block = Proc.new do |pdf|
    draw_crossword(pdf, :solved => false, :indexes => true)
    pdf.move_down PDF_CELL_SIZE
    if options[:include_solution]
      cursor = pdf.cursor
      draw_crossword(pdf, :solved => true, 
                          :at => [pdf.bounds.width - PDF_CELL_SIZE*(dimensions[:horizontal])/2, 
                                  pdf.cursor + PDF_CELL_SIZE*(dimensions[:vertical])/2],
                          :scale => 0.5,
                          :inverted => true)
      
      pdf.move_cursor_to cursor #- PDF_CELL_SIZE
    end
    pdf.move_down PDF_CELL_SIZE
    draw_definitions(pdf)
  end
  if file.is_a?(Prawn::Document)
    drawing_block.call(file)
  else
    Prawn::Document.generate(file, &drawing_block)
  end
end