Class: TeachingPrintables::TPDocument
- Inherits:
-
Object
- Object
- TeachingPrintables::TPDocument
- Includes:
- Prawn::View
- Defined in:
- lib/teaching_printables/tp_document.rb
Overview
Creates quadrille rulings on paper. Delegates Prawn methods to Prawn::Document.
Constant Summary collapse
- DOC_OPTIONS_DEFAULT =
{ :page_layout => :portrait, :margin => 0 }
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ TPDocument
constructor
A new instance of TPDocument.
- #method_missing(m, *args) ⇒ Object
- #page_height ⇒ Object
- #page_width ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ TPDocument
Returns a new instance of TPDocument.
13 14 15 16 |
# File 'lib/teaching_printables/tp_document.rb', line 13 def initialize(args={}) args = DOC_OPTIONS_DEFAULT.merge(args).merge({skip_page_creation: true}) @document = Prawn::Document.new(args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/teaching_printables/tp_document.rb', line 34 def method_missing(m, *args) method = m.to_s if document.class.public_method_defined?(method) document.send(method,*args) elsif method.start_with?("page_") page_method = method[5..-1] if state.page.class.public_method_defined?(page_method) state.page.send(page_method,*args) else raise NoMethodError.new("Can't find method",page_method) end else super end end |
Instance Method Details
#page_height ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/teaching_printables/tp_document.rb', line 26 def page_height if page_layout == :portrait height = PDF::Core::PageGeometry::SIZES[page_size][1] else height = PDF::Core::PageGeometry::SIZES[page_size][0] end end |
#page_width ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/teaching_printables/tp_document.rb', line 18 def page_width if page_layout == :portrait width = PDF::Core::PageGeometry::SIZES[page_size][0] else width = PDF::Core::PageGeometry::SIZES[page_size][1] end end |