Class: TeachingPrintables::GridSheet
- Inherits:
-
Object
- Object
- TeachingPrintables::GridSheet
- Extended by:
- Forwardable
- Includes:
- Prawn::View
- Defined in:
- lib/teaching_printables/grid_sheet/grid_sheet.rb
Direct Known Subclasses
Constant Summary collapse
- GRID_OPTIONS_DEFAULT =
{ columns: 2, rows: 2, gutter: 0, column_width: 100, row_height: 100 }
Instance Attribute Summary collapse
-
#column_width ⇒ Object
readonly
Returns the value of attribute column_width.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#gutter ⇒ Object
readonly
Returns the value of attribute gutter.
-
#row_height ⇒ Object
readonly
Returns the value of attribute row_height.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #add_content(content_array) ⇒ Object
-
#initialize(args = {}, doc = nil) ⇒ GridSheet
constructor
A new instance of GridSheet.
- #place_contents_in_gridbox(obj) ⇒ Object
- #update_grid_options(options) ⇒ Object
Constructor Details
#initialize(args = {}, doc = nil) ⇒ GridSheet
Returns a new instance of GridSheet.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 21 def initialize(args={},doc=nil) if !doc @document = Prawn::Document.new(args.merge({skip_page_creation: true })) elsif doc.kind_of?(Prawn::Document) @document = doc else raise ArgumentError, "Expecting Prawn::Document", caller end @font_size = 60 (GRID_OPTIONS_DEFAULT.merge(args)) end |
Instance Attribute Details
#column_width ⇒ Object (readonly)
Returns the value of attribute column_width.
10 11 12 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 10 def column_width @column_width end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
10 11 12 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 10 def columns @columns end |
#gutter ⇒ Object (readonly)
Returns the value of attribute gutter.
10 11 12 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 10 def gutter @gutter end |
#row_height ⇒ Object (readonly)
Returns the value of attribute row_height.
10 11 12 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 10 def row_height @row_height end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
10 11 12 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 10 def rows @rows end |
Instance Method Details
#add_content(content_array) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 41 def add_content(content_array) @document.define_grid() content_array.each_with_index {|obj,ind| if ind%(@rows*@columns)==0 @document.start_new_page end subs = ind2sub([@rows,@columns],ind%(@rows*@columns)) @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
59 60 61 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 59 def place_contents_in_gridbox(obj) text obj.to_s, fit: [@column_width,@row_height] end |
#update_grid_options(options) ⇒ Object
35 36 37 38 39 |
# File 'lib/teaching_printables/grid_sheet/grid_sheet.rb', line 35 def () .each do |k,v| instance_variable_set("@#{k}", [k]) unless [k].nil? end end |