Class: DotGrid::Document
- Inherits:
-
Object
- Object
- DotGrid::Document
- Defined in:
- lib/dot_grid/document.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#margin ⇒ Object
Returns the value of attribute margin.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#page_size ⇒ Object
Returns the value of attribute page_size.
-
#page_types ⇒ Object
Returns the value of attribute page_types.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#pdf ⇒ Object
Returns the value of attribute pdf.
Instance Method Summary collapse
- #create_pages(params) ⇒ Object
- #generate ⇒ Object
-
#initialize(params = {}) ⇒ Document
constructor
A new instance of Document.
- #parse_page_size(page_size) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Document
Returns a new instance of Document.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dot_grid/document.rb', line 14 def initialize(params = {}) @file_name = params[:file_name] || "dotgrid.pdf" @page_size = params[:page_size] ? parse_page_size(params[:page_size]) : "LETTER" @orientation = params[:orientation] ? params[:orientation].downcase.to_sym : :portrait @margin = params[:margin] || 0.0 @page_types = params[:page_types] ? params[:page_types].downcase.split(",").map { |w| w.strip } : ["planner"] @pdf = Prawn::Document.new(margin: margin, page_size: page_size, skip_page_creation: true, page_layout: orientation) @pages = create_pages(params.merge({pdf: pdf})) end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def document @document end |
#file_name ⇒ Object
Returns the value of attribute file_name.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def file_name @file_name end |
#margin ⇒ Object
Returns the value of attribute margin.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def margin @margin end |
#orientation ⇒ Object
Returns the value of attribute orientation.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def orientation @orientation end |
#page_size ⇒ Object
Returns the value of attribute page_size.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def page_size @page_size end |
#page_types ⇒ Object
Returns the value of attribute page_types.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def page_types @page_types end |
#pages ⇒ Object
Returns the value of attribute pages.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def pages @pages end |
#pdf ⇒ Object
Returns the value of attribute pdf.
3 4 5 |
# File 'lib/dot_grid/document.rb', line 3 def pdf @pdf end |
Instance Method Details
#create_pages(params) ⇒ Object
30 31 32 33 34 |
# File 'lib/dot_grid/document.rb', line 30 def create_pages(params) page_types.map do |p| DotGrid::Page::Factory.build(p, params.clone) end end |
#generate ⇒ Object
36 37 38 39 |
# File 'lib/dot_grid/document.rb', line 36 def generate pages.each { |page| page.generate } pdf.render_file file_name end |
#parse_page_size(page_size) ⇒ Object
25 26 27 28 |
# File 'lib/dot_grid/document.rb', line 25 def parse_page_size(page_size) return page_size unless p = /(?'w'\d+\.{0,1}\d*)x(?'h'\d+\.{0,1}\d*)(?'u'[a-z]{2})/.match(page_size) return [p[:w].to_f.send(p[:u]), p[:h].to_f.send(p[:u])] end |