module TeachingPrintables::Shapeable

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

Attributes

rule_unit[RW]

Public Instance Methods

create_tens_and_ones_shapes(options={}) click to toggle source
# 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_height() click to toggle source
# File lib/teaching_printables/shapeable.rb, line 12
def rule_height
  bounds.top - bounds.bottom
end
rule_width() click to toggle source
# File lib/teaching_printables/shapeable.rb, line 15
def rule_width 
  bounds.right - bounds.left
end

Private Instance Methods

parse_options(options) click to toggle source
# File lib/teaching_printables/shapeable.rb, line 66
def parse_options(options)
  allowed_parameters = [:rule_unit]
  options.each do |k,v|
    puts "@#{k.to_s}"
    instance_variable_set("@#{k.to_s}",v) if allowed_parameters.include?(k)
  end
end