Class: TeachingPrintables::GridSheet

Inherits:
Object
  • Object
show all
Includes:
Prawn::View
Defined in:
lib/teaching_printables/grid_sheet/grid_sheet.rb

Direct Known Subclasses

PictureGridSheet

Constant Summary collapse

GRID_OPTIONS_DEFAULT =
{
  columns: 2,
  rows: 2,
  gutter: 0,
  column_width: 100,
  row_height: 100
}

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ GridSheet

Returns a new instance of GridSheet.



15
16
17
18
19
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 15

def initialize(args={})
  @document = Prawn::Document.new(args)
  @font_size = 60
  update_grid_options(args)
end

Instance Method Details

#make_grid(content_array) ⇒ Object



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

def make_grid(content_array)
  puts grid_options
  @document.define_grid(grid_options)
  content_array.each_with_index {|obj,ind|
  
    if ind > 0 && ind%10==0
      @document.start_new_page
    end
  
    subs = ind2sub([@rows,@columns],ind%10)
    @document.grid(subs[0],subs[1]).bounding_box do
      #place_contents_in_gridbox(obj)
      @document.text_box obj.to_s, align: :center, valign: :center, size: @font_size, overflow: :shrink_to_fit
    end
  }
end

#place_contents_in_gridbox(obj) ⇒ Object



46
47
48
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 46

def place_contents_in_gridbox(obj)
  text obj.to_s, fit: [@column_width,@row_height]
end

#update_grid_options(options) ⇒ Object



21
22
23
24
25
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 21

def update_grid_options(options)
  GRID_OPTIONS_DEFAULT.each do |k,v|
    instance_variable_set("@#{k}", options[k]) unless options[k].nil?
  end
end