class Mork::Grid
@private The Grid
is a set of expectations on what the response sheet should look like It knows nothing about the actual scanned image. All returned values are in the arbitrary units given in the configuration file
Public Class Methods
Calling Grid.new
without arguments creates the default boilerplate Grid
# File lib/mork/grid.rb, line 11 def initialize(options=nil) @params = default_grid if File.exists?('layout.yml') @params.deeper_merge! symbolize YAML.load_file('layout.yml') end case options when NilClass # do nothing when Hash @params.deeper_merge! symbolize options when String @params.deeper_merge! symbolize YAML.load_file(options) else fail ArgumentError, "Invalid parameter in the Grid constructor: #{options.class.inspect}" end end
Public Instance Methods
# File lib/mork/grid.rb, line 48 def barcode_bits @params[:barcode][:bits].to_i end
# File lib/mork/grid.rb, line 60 def choice_threshold @params[:items][:threshold].to_f end
@private this is the default grid! default units are millimiters
# File lib/mork/grid_const.rb, line 6 def default_grid { # size of the paper sheet page_size: { width: 210, # A4 height: 297 }, # size, location, search parameters of registration marks reg_marks: { margin: 10, # from sheet edge to registration mark center radius: 3, # of the registration circle offset: 2, # distance between page edge and registraton mark search area crop: 20, # size of square where the regmark should be located dilate: 5, # set to >0 to apply a dilate IM operation blur: 2, # set to >0 to apply a blur IM operation contrast: 20 # minimum contrast between registration mark circles and the white paper }, # you can place multiple elements in the header; title is the only default header: { title: { top: 15, left: 15, width: 160, height: 12, size: 12, box: false } }, # questions and answers items: { threshold: 0.75, # how much darker a marked cell should be compared to cal cells columns: 4, column_width: 44, rows: 30, left: 11, # distance from the top-left registration mark... top: 55, # ...to the center of the first choice cell x_spacing: 7, # between choices y_spacing: 7, # between rows cell_width: 6, # choice cell size cell_height: 5, # choice cell size max_cells: 5, # the maximum number of choices per question font_size: 9, # for the question number and choice letters number_width: 8, # width of question number text box number_margin: 2 # distance between right side of q num and left side of first choice cell }, # unique sheet ID as a binary barcode barcode: { bits: 38, left: 15, width: 3, height: 3, spacing: 4 }, # student's unique id uid: { digits: 6, left: 150, top: 30, width: 50, height: 40, cell_width: 4, cell_height: 3, box: true } } end
# File lib/mork/grid.rb, line 44 def max_choices_per_question @params[:items][:max_cells].to_i end
# File lib/mork/grid.rb, line 40 def max_questions columns * rows end
# File lib/mork/grid.rb, line 36 def options @params end
# File lib/mork/grid.rb, line 56 def rm_blur @params[:reg_marks][:blur].to_i end
# File lib/mork/grid.rb, line 52 def rm_dilate @params[:reg_marks][:dilate].to_i end
Puts out the Grid
parameters in YAML format; the entire hash is displayed if no arguments are given; you can specify what to show by passing one of: :page_size, :reg_marks, :header, :items, :barcode
# File lib/mork/grid.rb, line 31 def show(subset=nil) out = subset ? @params[subset] : @params puts out.to_yaml end
Private Instance Methods
# File lib/mork/grid.rb, line 103 def barcode_height() @params[:barcode][:height].to_f end
# File lib/mork/grid.rb, line 104 def barcode_width() @params[:barcode][:width].to_f end
# File lib/mork/grid.rb, line 88 def cal_cell_x reg_frame_width - cell_spacing end
# File lib/mork/grid.rb, line 106 def cell_height() @params[:items][:cell_height].to_f end
# File lib/mork/grid.rb, line 107 def cell_spacing() @params[:items][:x_spacing].to_f end
# File lib/mork/grid.rb, line 105 def cell_width() @params[:items][:cell_width].to_f end
cell_x
(q,c)
the distance from the registration frame to the left edge of the c-th choice cell of the q-th question
# File lib/mork/grid.rb, line 80 def cell_x(q,c) item_x(q) + cell_spacing * c end
cell_y
(q)
the distance from the registration frame to the top edge of all choice cells in the q-th question
# File lib/mork/grid.rb, line 72 def cell_y(q) first_y + item_spacing * (q % rows) - cell_height / 2 end
# File lib/mork/grid.rb, line 109 def column_width() @params[:items][:column_width].to_f end
# File lib/mork/grid.rb, line 113 def columns() @params[:items][:columns] end
# File lib/mork/grid.rb, line 110 def first_x() @params[:items][:left].to_f end
# File lib/mork/grid.rb, line 111 def first_y() @params[:items][:top].to_f end
# File lib/mork/grid.rb, line 108 def item_spacing() @params[:items][:y_spacing].to_f end
# File lib/mork/grid.rb, line 84 def item_x(q) first_x + column_width * (q / rows) - cell_width / 2 end
# File lib/mork/grid.rb, line 121 def page_height() @params[:page_size][:height].to_f end
# File lib/mork/grid.rb, line 120 def page_width() @params[:page_size][:width].to_f end
# File lib/mork/grid.rb, line 115 def reg_crop() @params[:reg_marks][:crop].to_f end
# File lib/mork/grid.rb, line 118 def reg_frame_height() page_height - reg_margin * 2 end
# File lib/mork/grid.rb, line 117 def reg_frame_width() page_width - reg_margin * 2 end
# File lib/mork/grid.rb, line 122 def reg_margin() @params[:reg_marks][:margin].to_f end
# File lib/mork/grid.rb, line 119 def reg_min_contrast() @params[:reg_marks][:contrast] end
# File lib/mork/grid.rb, line 116 def reg_off() @params[:reg_marks][:offset].to_f end
# File lib/mork/grid.rb, line 123 def reg_radius() @params[:reg_marks][:radius].to_f end
# File lib/mork/grid.rb, line 114 def reg_search() @params[:reg_marks][:search].to_f end
# File lib/mork/grid.rb, line 112 def rows() @params[:items][:rows] end
# File lib/mork/grid.rb, line 130 def uid_cell_height() @params[:uid][:cell_height].to_f end
# File lib/mork/grid.rb, line 129 def uid_cell_width() @params[:uid][:cell_width].to_f end
# File lib/mork/grid.rb, line 124 def uid_digits() @params[:uid][:digits].to_i end
# File lib/mork/grid.rb, line 128 def uid_height() @params[:uid][:height].to_f end
# File lib/mork/grid.rb, line 127 def uid_width() @params[:uid][:width].to_f end
# File lib/mork/grid.rb, line 125 def uid_x() @params[:uid][:left].to_f end
# File lib/mork/grid.rb, line 126 def uid_y() @params[:uid][:top].to_f end