Class: Sugpoko::Base

Inherits:
Object
  • Object
show all
Includes:
Prawn::View
Defined in:
lib/sugpoko/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



25
26
27
28
29
# File 'lib/sugpoko/base.rb', line 25

def initialize(options = {})
  @data = options[:data]
  @pdf = self
  configure options
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/sugpoko/base.rb', line 3

def data
  @data
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



3
4
5
# File 'lib/sugpoko/base.rb', line 3

def page_size
  @page_size
end

#pdfObject (readonly)

Returns the value of attribute pdf.



3
4
5
# File 'lib/sugpoko/base.rb', line 3

def pdf
  @pdf
end

Instance Method Details

#base_attributesObject



15
16
17
18
19
20
21
22
23
# File 'lib/sugpoko/base.rb', line 15

def base_attributes
  {
    pdf: pdf,
    width: width - margin * 2,
    height: height - margin * 2,
    position: [0, pdf.cursor],
    data: data
  }
end

#configure(options = {}) ⇒ Object



31
32
# File 'lib/sugpoko/base.rb', line 31

def configure(options = {})
end

#default_optionsObject



50
51
52
53
54
55
# File 'lib/sugpoko/base.rb', line 50

def default_options
  @default_options ||= {
    page_size: [width, height],
    page_layout: :portrait
  }
end

#documentObject



46
47
48
# File 'lib/sugpoko/base.rb', line 46

def document
  @document ||= Prawn::Document.new(default_options)
end

#draw(klass, options = {}) ⇒ Object



11
12
13
# File 'lib/sugpoko/base.rb', line 11

def draw(klass, options = {})
  klass.new(base_attributes.merge(options)).generate
end

#generateObject



7
8
9
# File 'lib/sugpoko/base.rb', line 7

def generate
  raise '#generate not defined'
end

#heightObject



38
39
40
# File 'lib/sugpoko/base.rb', line 38

def height
  11.in
end

#marginObject



42
43
44
# File 'lib/sugpoko/base.rb', line 42

def margin
  0.5.in
end

#widthObject



34
35
36
# File 'lib/sugpoko/base.rb', line 34

def width
  8.5.in
end