Module: TeachingPrintables::Shapeable

Defined in:
lib/teaching_printables/shapeable.rb

Overview

Creates quadrille rulings on paper. Delegates Prawn methods to Prawn::Document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rule_unitObject

Returns the value of attribute rule_unit.



7
8
9
# File 'lib/teaching_printables/shapeable.rb', line 7

def rule_unit
  @rule_unit
end

Instance Method Details

#create_tens_and_ones_shapes(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/teaching_printables/shapeable.rb', line 19

def create_tens_and_ones_shapes(options={})
  # Start at position 3cm, 3cm from top left corner.  Keep drawing shapes until end of page
  
  fill_colors_enum = %W[red blue green orange].cycle
  
  if (page_number ==0) || (options[:start_new_page] == true)
    start_new_page
  end

  
  shape_position = [3.cm, rule_height-2.cm]
  page_height = rule_height - 4.cm
  remaining_rows = (page_height / rule_unit).floor 
  shapes_rows_arr = []
  
  while remaining_rows > 2
    shapes_rows_arr<<rand(3..[11,remaining_rows].min)
    remaining_rows = remaining_rows-shapes_rows_arr.last
  end
  
  shapes_rows_arr.each {|nrows|
    ones = rand(0..9)
    svg( SVGComponents::tens_and_ones_shape_svg(nrows-2,ones,fill_color=fill_colors_enum.next),
      width: 10*rule_unit, 
      height: (nrows-1)*rule_unit, 
      at: [shape_position[0],shape_position[1]-rule_unit])
    
      @document.fill_color = "FFFFFF"
      fill_and_stroke_rectangle [14.cm, shape_position[1]-1*rule_unit], 2.cm, 2.cm
      fill_and_stroke_rectangle [16.cm, shape_position[1]-1*rule_unit], 2.cm, 2.cm
      @document.fill_color = "000000"
      text_box "tens", :at => [14.cm, shape_position[1]-1*rule_unit], :width => 2.cm, :align => :center
      text_box "ones", :at => [16.cm, shape_position[1]-1*rule_unit], :width => 2.cm, :align => :center
          
    
      if ones == 0
        shape_position[1] = shape_position[1]-(nrows-1).cm
      else
        shape_position[1] = shape_position[1]-nrows.cm 
      end
      
  }  
   
end

#rule_heightObject



12
13
14
# File 'lib/teaching_printables/shapeable.rb', line 12

def rule_height
  bounds.top - bounds.bottom
end

#rule_widthObject



15
16
17
# File 'lib/teaching_printables/shapeable.rb', line 15

def rule_width 
  bounds.right - bounds.left
end