lib/mork/sheet_pdf.rb in mork-0.0.6 vs lib/mork/sheet_pdf.rb in mork-0.0.7

- old
+ new

@@ -1,15 +1,19 @@ require 'prawn' module Mork class SheetPDF < Prawn::Document - def initialize(grid, info) - @grid = grid + def initialize(content, grid=Grid.new) + @grid = case grid.class.to_s + when "String"; Grid.new grid + when "Mork::Grid"; grid + else raise "Invalid initialization parameter" + end super my_page_params - # @info should be an array of hashes, one per page; + # @content should be an array of hashes, one per page; # convert to array if a single hash was passed - @info = info.class == Hash ? [info] : info + @content = content.class == Hash ? [content] : content process end def save(fn) render_file fn @@ -21,20 +25,20 @@ private def process # for each response sheet - @info.each_with_index do |info, i| + @content.each_with_index do |content, i| start_new_page if i>0 fill_color "000000" stroke_color "000000" line_width 0.3 registration_marks - calibration_and_code info[:code] - header info[:header] - control info[:control] if info[:control] - questions_and_choices info[:choices] + calibration_and_code content[:code] + header content[:header] + control content[:control] if content[:control] + questions_and_choices content[:choices] end end def my_page_params { @@ -62,35 +66,35 @@ rectangle c[:p], c[:w], c[:h] end end end - def control(info) + def control(content) font_size @grid.pdf_control_size do - text_box info[:string], at: @grid.pdf_control_xy, + text_box content[:string], at: @grid.pdf_control_xy, width: @grid.pdf_control_width, align: :right stroke do font_size stroke_color "ff0000" # dark a = @grid.pdf_ctrl_area_dark rounded_rectangle a[:p], a[:w], a[:h], [a[:h], a[:w]].min / 2 fill_color "ff0000" - draw_text info[:labels][0], at: @grid.pdf_dark_control_letter_xy + draw_text content[:labels][0], at: @grid.pdf_dark_control_letter_xy # light a = @grid.pdf_ctrl_area_light rounded_rectangle a[:p], a[:w], a[:h], [a[:h], a[:w]].min / 2 fill_color "ff0000" - draw_text info[:labels][1], at: @grid.pdf_light_control_letter_xy + draw_text content[:labels][1], at: @grid.pdf_light_control_letter_xy end end end - def header(info) - info.each do |k,v| + def header(content) + content.each do |k,v| font_size @grid.pdf_header_size(k) do if @grid.pdf_header_boxed?(k) bounding_box @grid.pdf_header_xy(k), width: @grid.pdf_header_width(k), height: @grid.pdf_header_height(k) do stroke_bounds bounding_box @grid.pdf_header_padding(k), width: @grid.pdf_header_width(k) do @@ -102,35 +106,35 @@ end end end end - def questions_and_choices(info) + def questions_and_choices(content) stroke do - info.length.times do |q| + content.length.times do |q| fill_color "000000" text_box "#{q+1}", at: @grid.pdf_qnum_xy(q), width: @grid.pdf_qnum_width, align: :right, size: @grid.pdf_qnum_size stroke_color "ff0000" font_size @grid.pdf_chlett_size - info[q].times do |c| + content[q].times do |c| a = @grid.pdf_choice_cell_area q, c rounded_rectangle a[:p], a[:w], a[:h], [a[:h], a[:w]].min / 2 fill_color "ff0000" draw_text (65+c).chr, at: @grid.pdf_choice_letter_xy(q, c) end end end end # def nquestions - # @info[:choices].length + # @content[:choices].length # end # # def nchoices(i) - # @info[:choices][i] + # @content[:choices][i] # end end end class Fixnum